package com.css.fxfzypg.manage.building.service.impl;

import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.css.fxfzypg.base.annotation.*;
import com.css.fxfzypg.base.exception.ServiceException;
import com.css.fxfzypg.cache.DivisionCache;
import com.css.fxfzypg.constants.BuildingStructureConstants;
import com.css.fxfzypg.constants.FxfzConstants;
import com.css.fxfzypg.manage.building.repository.BuildingReqository;
import com.css.fxfzypg.manage.building.repository.entity.BuildingEntity;
import com.css.fxfzypg.manage.building.service.BuildingService;
import com.css.fxfzypg.manage.building.verify.BuildingExcelVerifyHandler;
import com.css.fxfzypg.manage.building.vo.*;
import com.css.fxfzypg.manage.sampling.repository.SamplingReqository;
import com.css.fxfzypg.modules.surveytaskmanage.service.FieldSurveyTaskService;
import com.css.fxfzypg.modules.surveytaskmanage.vo.TaskVo;
import com.css.fxfzypg.util.*;
import com.css.fxfzypg.web.PlatformSessionContext;
import com.css.fxfzypg.zcpt.sys.entity.SUser;
import com.css.fxfzypg.zcpt.sys.service.SUserService;
import com.css.fxfzypg.zcpt.sys.service.SysAreaService;
import com.css.fxfzypg.zcpt.sys.service.SysRoleService;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.URLEncoder;
import java.util.*;

@Slf4j
@Service
public class BuildingServiceImpl implements BuildingService {

    @Autowired
    BuildingReqository buildingReqository;

    @Autowired
    SysAreaService sysAreaService;

    @Autowired
    SUserService sUserService;

    @Autowired
    SysRoleService sysRoleService;

    @Autowired
    FieldSurveyTaskService fieldSurveyTaskService;

    @Autowired
    BuildingExcelVerifyHandler buildingExcelVerifyHandler;

    @Autowired
    SamplingReqository samplingReqository;

    @Override
    public boolean saveBuilding(BuildingEntity buildingEntity) throws UnsupportedEncodingException {
        String uuid = UUIDGenerator.getUUID();
        buildingEntity.setId(uuid);
        String divisionIds = sysAreaService.getIdByCondition(URLEncoder.encode(buildingEntity.getProvince(), "UTF-8"), URLEncoder.encode(buildingEntity.getCity(), "UTF-8"), URLEncoder.encode(buildingEntity.getCounty(), "UTF-8"));
        buildingEntity.setProvinceId(divisionIds.split("_")[0]);
        buildingEntity.setCityId(divisionIds.split("_")[1]);
        buildingEntity.setCountyId(divisionIds.split("_")[2]);
        buildingEntity.setCreateTime(new Date());
        buildingEntity.setIsSubmit("0");
        buildingEntity.setDelFlag("0");
        String longitude = buildingEntity.getLongitude();
        String latitude = buildingEntity.getLatitude();
        String geom = "POINT(" + longitude + " " + latitude + ")";
        buildingEntity.setGeom(geom);
        return buildingReqository.saveBuilding(buildingEntity);
    }

    @Override
    public boolean saveAndSubmit(BuildingEntity buildingEntity) throws UnsupportedEncodingException {
        String uuid = UUIDGenerator.getUUID();
        buildingEntity.setId(uuid);
        String divisionIds = sysAreaService.getIdByCondition(URLEncoder.encode(buildingEntity.getProvince(), "UTF-8"), URLEncoder.encode(buildingEntity.getCity(), "UTF-8"), URLEncoder.encode(buildingEntity.getCounty(), "UTF-8"));
        buildingEntity.setProvinceId(divisionIds.split("_")[0]);
        buildingEntity.setCityId(divisionIds.split("_")[1]);
        buildingEntity.setCountyId(divisionIds.split("_")[2]);
        buildingEntity.setCreateTime(new Date());
        buildingEntity.setSubmitter(buildingEntity.getCreateName());
        buildingEntity.setSubmitterId(buildingEntity.getCreateId());
        buildingEntity.setSubmitTime(new Date());
        buildingEntity.setIsSubmit("1");
        buildingEntity.setDelFlag("0");
        String longitude = buildingEntity.getLongitude();
        String latitude = buildingEntity.getLatitude();
        String geom = "POINT(" + longitude + " " + latitude + ")";
        buildingEntity.setGeom(geom);
        return buildingReqository.saveBuilding(buildingEntity);
    }


    @Override
    public Map<String, Object> querySubmitOrNot(String submitFlag, String taskCode, int curPage, int pageSize, String userId) {
        return buildingReqository.querySubmitOrNot(submitFlag, taskCode, curPage, pageSize, userId);
    }

    @Override
    public boolean updateIsSubmit(Map<String, String> map) {
        return buildingReqository.updateIsSubmit(map);
    }

    @Override
    public BuildingEntity queryData(String id) {
        return buildingReqository.queryData(id);
    }

    @Override
    public boolean modifyData(BuildingEntity buildingEntity) {
        return buildingReqository.modifyData(buildingEntity);
    }

    @Override
    public boolean modifyAndSubmit(BuildingEntity buildingEntity) {
        buildingEntity.setIsSubmit("1");
        buildingEntity.setSubmitter(buildingEntity.getCreateName());
        buildingEntity.setSubmitterId(buildingEntity.getCreateId());
        buildingEntity.setSubmitTime(new Date());
        return buildingReqository.modifyData(buildingEntity);
    }

    @Override
    public Map<String, Object> queryBuildingData(HttpServletRequest request, BuildingParams queryParams, int curPage, int pageSize) {
        System.err.println("获取建筑物列表数据-------");
        String userId = PlatformSessionContext.getUserID();
        String user = sUserService.getSUser(userId);
        SUser sUser = CreateGson.createGson().fromJson(user, SUser.class);
        String role = sysRoleService.getRoleByUserId(userId);
        List<Map> maps = JSONObject.parseArray(role, Map.class);//一个人可能有多个角色
        //当前登录人所有的角色
        StringBuilder roles = new StringBuilder();
        for (int i = 0; i < maps.size(); i++) {
            Map map = maps.get(i);
            roles.append(map.get("roleCode") + ",");
        }
        String allRole = roles.toString();
        String provinceId = sUser.getProvinceId();//省id
        //国家管理员和业务员有可能 是组长 组员,不可能是省管理员 省业务员
        //省级管理员和业务员有可能 是组长 组员,不可能是国家管理员  国家业务员,也有可能参与了其他省的任务,需要显示省数据和他参与的
        //任务管理员 可以查看 修改 删除 当前任务下所有的建筑物单体
        //任务管理员是否有可能是国家管理员/业务员    省管理员/业务员   是否参与其他任务,是其他任务的组长 组员
        //任务管理员+省管理员/省业务员  这个省数据+任务管理员的任务的数据+任务管理员这个人参与过的

        //获取所有任务编号和任务管理员
        List<TaskVo> taskManagers = fieldSurveyTaskService.getTaskManagers();
        //当前登录人(任务管理员)新建的所有任务
        List<String> taskCodeList = new ArrayList<>();
        if (!PlatformObjectUtils.isEmpty(taskManagers)) {
            for (TaskVo taskVo : taskManagers) {
                String createUser = taskVo.getCreateUser();
                if (createUser.equals(userId)) {
                    taskCodeList.add(taskVo.getTaskNum());
                }
            }
        }
        //国家管理员 查看  修改  删除
        if (allRole.contains(FxfzConstants.YPG_COUN_GL_ROLE)) {
            System.err.println("登录人:" + userId + ",角色是 国家管理员------");
            Map<String, Object> map = buildingReqository.queryBuildingData(request, queryParams, curPage, pageSize);
            List<BuildingParams> buildingParams = (List<BuildingParams>) map.get("rows");
            List<BuildingParams> list = new ArrayList<>();
            if (buildingParams != null && buildingParams.size() > 0) {
                for (BuildingParams buildingData : buildingParams) {
                    buildingData.setFlag("2");
                    list.add(buildingData);
                }
            }
            map.put("rows", list);
            return map;
        }
        //国家业务员  查看 (如果是本人创建的或者组长需要加修改删除)
        else if (allRole.contains(FxfzConstants.YPG_COUN_YW_ROLE)) {
            System.err.println("登录人:" + userId + ",角色是 国家业务员------");
            List<BuildingParams> list = new ArrayList<>();
            Map<String, Object> map = buildingReqository.queryBuildingData(request, queryParams, curPage, pageSize);
            List<BuildingParams> buildingParams = (List<BuildingParams>) map.get("rows");
            if (buildingParams != null && buildingParams.size() > 0) {
                for (BuildingParams buildingData : buildingParams) {
                    String createId = buildingData.getCreateId();
                    String groupLeaderId = fieldSurveyTaskService.getGroupLeaderId(buildingData.getTaskCode());//组长
                    if (PlatformObjectUtils.isEmpty(groupLeaderId)) {
                        groupLeaderId = "无组长";
                    }
                    if (userId.equals(createId)) {
                        System.err.println("登录人:" + userId + ",角色是 国家业务员------本人创建");
                        buildingData.setFlag("2");
                    } else if (groupLeaderId.equals(userId)) {
                        System.err.println("登录人:" + userId + ",角色是 国家业务员------组长");
                        buildingData.setFlag("2");
                    } else {
                        System.err.println("登录人:" + userId + ",角色是 国家业务员------");
                        buildingData.setFlag("1");
                    }
                    //任务管理员
                    if (taskCodeList.contains(buildingData.getTaskCode())) {
                        System.err.println("登录人:" + userId + ",是 " + buildingData.getTaskCode() + "的任务管理员------");
                        buildingData.setFlag("2");
                    }
                    list.add(buildingData);
                }
            }
            map.put("rows", list);
            return map;
        }
        //省级管理员(各省查看各省的)  查看  修改  删除
        else if (allRole.contains(FxfzConstants.YPG_PRI_GL_ROLE)) {
            System.err.println("登录人:" + userId + ",角色是 省级管理员------");
            //获取该省所有数据和管理员参与的
            Map<String, Object> map = buildingReqository.queryBuildingDataByProvince(queryParams, curPage, pageSize, userId, provinceId, taskCodeList);
            List<BuildingParams> list = new ArrayList<>();
            List<BuildingParams> buildingParams = (List<BuildingParams>) map.get("rows");
            if (buildingParams != null && buildingParams.size() > 0) {
                for (BuildingParams buildingData : buildingParams) {
                    //判断该业务员参与的其他省的  是否为组员
                    List<Map<String, Object>> teamMembers = fieldSurveyTaskService.getTeamMembers(buildingData.getTaskCode());//组员
                    if (!PlatformObjectUtils.isEmpty(teamMembers) && teamMembers.size() > 0) {
                        for (Map<String, Object> map2 : teamMembers) {
                            String teamMember = map2.get("user_id").toString();
                            if (!PlatformObjectUtils.isEmpty(teamMember)) {
                                if (userId.equals(teamMember)) {
                                    System.err.println("登录人:" + userId + ",任务编号:" + buildingData.getTaskCode() + ",该任务中的组员------");
                                    buildingData.setFlag("1");
                                    break;
                                }
                            }
                        }
                    }
                    //判断该业务员参与的其他省的    或者自己参与的是否为组长或本人
                    String createId = buildingData.getCreateId();
                    String groupLeaderId = fieldSurveyTaskService.getGroupLeaderId(buildingData.getTaskCode());//组长
                    if (PlatformObjectUtils.isEmpty(groupLeaderId)) {
                        groupLeaderId = "无组长";
                    }
                    if (userId.equals(createId) || groupLeaderId.equals(createId)) {
                        buildingData.setFlag("2");
                    }
                    //判断是否为自己省
                    if (buildingData.getProvinceId() != null && buildingData.getProvinceId().equals(provinceId)) {
                        buildingData.setFlag("2");
                    }
                    //判断是否为任务管理员
                    if (taskCodeList.contains(buildingData.getTaskCode())) {
                        buildingData.setFlag("2");
                    }
                    list.add(buildingData);
                }
                map.put("rows", list);
                return map;
            }
        }
        //省级业务员(各省查看各省的)查看   如果是本人创建的或者组长需要加修改删除)
        else if (allRole.contains(FxfzConstants.YPG_PRI_YW_ROLE)) {
            System.err.println("登录人:" + userId + ",角色是 省级业务员------");
            //获取该省所有数据和业务员参与的
            Map<String, Object> map = buildingReqository.queryBuildingDataByProvince(queryParams, curPage, pageSize, userId, provinceId, taskCodeList);
            List<BuildingParams> list = new ArrayList<>();
            List<BuildingParams> buildingParams = (List<BuildingParams>) map.get("rows");
            if (buildingParams != null && buildingParams.size() > 0) {
                for (BuildingParams buildingData : buildingParams) {
                    //判断是否为自己省
                    if (buildingData.getProvinceId() != null && buildingData.getProvinceId().equals(provinceId)) {
                        buildingData.setFlag("1");
                    }
                    //判断该业务员参与的其他省的  是否为组员
                    List<Map<String, Object>> teamMembers = fieldSurveyTaskService.getTeamMembers(buildingData.getTaskCode());//组员
                    if (!PlatformObjectUtils.isEmpty(teamMembers) && teamMembers.size() > 0) {
                        for (Map<String, Object> map2 : teamMembers) {
                            String teamMember = map2.get("user_id").toString();
                            if (!PlatformObjectUtils.isEmpty(teamMember)) {
                                if (userId.equals(teamMember)) {
                                    System.err.println("登录人:" + userId + ",任务编号:" + buildingData.getTaskCode() + ",该任务中的组员------");
                                    buildingData.setFlag("1");
                                    break;
                                }
                            }
                        }
                    }
                    //判断该业务员参与的其他省的    或者自己参与的是否为组长或本人
                    String createId = buildingData.getCreateId();
                    String groupLeaderId = fieldSurveyTaskService.getGroupLeaderId(buildingData.getTaskCode());//组长
                    if (PlatformObjectUtils.isEmpty(groupLeaderId)) {
                        groupLeaderId = "无组长";
                    }
                    if (userId.equals(createId) || groupLeaderId.equals(createId)) {
                        buildingData.setFlag("2");
                    }
                    //判断是否为任务管理员
                    if (taskCodeList.contains(buildingData.getTaskCode())) {
                        buildingData.setFlag("2");
                    }
                    list.add(buildingData);
                }
            }
            map.put("rows", list);
            return map;
        }

        //本人创建的或者组长或者是任务管理员:查看 修改 删除,或者是小组组员:查看
        System.err.println("登录人:" + userId + ",无国家/省角色------");
        Map<String, Object> map = buildingReqository.getBuildingDataByTeamMembers(request, queryParams, curPage, pageSize, userId, taskCodeList);
        List<BuildingParams> list = new ArrayList<>();
        List<BuildingParams> buildingParams = (List<BuildingParams>) map.get("rows");
        if (buildingParams != null && buildingParams.size() > 0) {
            for (BuildingParams buildingData : buildingParams) {
                //获取某任务下所有组员
                List<Map<String, Object>> teamMembers = fieldSurveyTaskService.getTeamMembers(buildingData.getTaskCode());//组员
                if (!PlatformObjectUtils.isEmpty(teamMembers) && teamMembers.size() > 0) {
                    for (Map<String, Object> map2 : teamMembers) {
                        String teamMember = map2.get("user_id").toString();
                        if (!PlatformObjectUtils.isEmpty(teamMember)) {
                            if (userId.equals(teamMember)) {
                                System.err.println("登录人:" + userId + ",任务编号:" + buildingData.getTaskCode() + ",该任务中的组员------");
                                buildingData.setFlag("1");
                                break;
                            }
                        }
                    }
                }
                String groupLeaderId = fieldSurveyTaskService.getGroupLeaderId(buildingData.getTaskCode());//组长
                if (PlatformObjectUtils.isEmpty(groupLeaderId)) {
                    groupLeaderId = "无组长";
                }
                //本人或者组长
                if (userId.equals(buildingData.getCreateId()) || userId.equals(groupLeaderId)) {
                    System.err.println("登录人:" + userId + ",本人创建或者组长------");
                    buildingData.setFlag("2");
                }
                //判断是否为任务管理员
                if (taskCodeList.contains(buildingData.getTaskCode())) {
                    buildingData.setFlag("2");
                }
                list.add(buildingData);
            }
        }
        map.put("rows", list);
        return map;
    }

    @Override
    public boolean deleteBuilding(String ids) {
        boolean res = true;
        for (String id : ids.split(",")) {
            res = buildingReqository.deleteBuilding(id);
            if (res == false) {
                break;
            }
        }
        return res;
    }

    @Override
    public Map<String, Object> getDataGroupByStructure(String taskCode, String userId) throws IllegalAccessException {
        BuildingStructureConstants buildingStructureConstants = new BuildingStructureConstants();
        Field[] fields = buildingStructureConstants.getClass().getDeclaredFields();
        HashMap<String, Object> map = new HashMap<>();
        for (Field field : fields) {
            ArrayList<BuildingVo> list = new ArrayList<>();
            String structure = field.get(buildingStructureConstants).toString();
            List<BuildingEntity> buildingEntityList = buildingReqository.getDataGroupByStructure(taskCode, structure);
            for (BuildingEntity buildingEntity : buildingEntityList) {
                String createId = buildingEntity.getCreateId();
                if (createId.equals(userId)) {
                    BuildingVo buildingVo = new BuildingVo();
                    buildingVo.setId(buildingEntity.getId());
                    buildingVo.setTaskCode(buildingEntity.getTaskCode());
                    buildingVo.setLongitude(buildingEntity.getLongitude());//经度
                    buildingVo.setLatitude(buildingEntity.getLatitude());//纬度
                    buildingVo.setTaskName(buildingEntity.getTaskName());
                    buildingVo.setBuildCode(buildingEntity.getBuildCode());
                    buildingVo.setBuildingStructure(buildingEntity.getBuildingStructure());
                    buildingVo.setFlag("1"); //0:不可查看,1:可以查看
                    list.add(buildingVo);
                } else {
                    BuildingVo buildingVo = new BuildingVo();
                    buildingVo.setId(buildingEntity.getId());
                    buildingVo.setTaskCode(buildingEntity.getTaskCode());
                    buildingVo.setLongitude(buildingEntity.getLongitude());//经度
                    buildingVo.setLatitude(buildingEntity.getLatitude());//纬度
                    buildingVo.setTaskName(buildingEntity.getTaskName());
                    buildingVo.setBuildCode(buildingEntity.getBuildCode());
                    buildingVo.setBuildingStructure(buildingEntity.getBuildingStructure());
                    buildingVo.setFlag("0"); //0:不可查看,1:可以查看
                    list.add(buildingVo);
                }
            }
            map.put(structure, list);
        }
        return map;
    }

    @Override
    public List<BuildingParams> queryBuildingMap(BuildingParams queryParams) {
        System.err.println("获取建筑物地图数据-------");
        String userId = PlatformSessionContext.getUserID();
        String user = sUserService.getSUser(userId);
        SUser sUser = CreateGson.createGson().fromJson(user, SUser.class);
        String role = sysRoleService.getRoleByUserId(userId);
        List<Map> maps = JSONObject.parseArray(role, Map.class);//一个人可能有多个角色
        //当前登录人所有的角色
        StringBuilder roles = new StringBuilder();
        for (int i = 0; i < maps.size(); i++) {
            Map map = maps.get(i);
            roles.append(map.get("roleCode") + ",");
        }
        String allRole = roles.toString();
        String provinceId = sUser.getProvinceId();//省id
        //获取所有任务编号和任务管理员
        List<TaskVo> taskManagers = fieldSurveyTaskService.getTaskManagers();
        //当前登录人(任务管理员)新建的所有任务
        List<String> taskCodeList = new ArrayList<>();
        //boolean flag = false;
        for (TaskVo taskVo : taskManagers) {
            String createUser = taskVo.getCreateUser();
            if (createUser.equals(userId)) {
                taskCodeList.add(taskVo.getTaskNum());
            }
        }
        //国家管理员和业务员有可能 是组长 组员,不可能是省管理员 省业务员
        //省级管理员和业务员有可能 是组长 组员,不可能是国家管理员  国家业务员,也有可能参与了其他省的任务,需要显示省数据和他参与的
        //国家管理员 查看  修改  删除
        if (allRole.contains(FxfzConstants.YPG_COUN_GL_ROLE)) {
            System.err.println("登录人:" + userId + ",角色是 国家管理员------");
            List<BuildingParams> buildingParams = buildingReqository.queryBuildingMap();
            List<BuildingParams> list = new ArrayList<>();
            if (buildingParams != null && buildingParams.size() > 0) {
                for (BuildingParams buildingData : buildingParams) {
                    buildingData.setFlag("2");
                    list.add(buildingData);
                }
            }
            return list;
        }
        //国家业务员  查看 (如果是本人创建的或者组长需要加修改删除)
        else if (allRole.contains(FxfzConstants.YPG_COUN_YW_ROLE)) {
            System.err.println("登录人:" + userId + ",角色是 国家业务员------");
            List<BuildingParams> list = new ArrayList<>();
            List<BuildingParams> buildingParams = buildingReqository.queryBuildingMap();
            if (buildingParams != null && buildingParams.size() > 0) {
                for (BuildingParams buildingData : buildingParams) {
                    String createId = buildingData.getCreateId();
                    String groupLeaderId = fieldSurveyTaskService.getGroupLeaderId(buildingData.getTaskCode());//组长
                    if (PlatformObjectUtils.isEmpty(groupLeaderId)) {
                        groupLeaderId = "无组长";
                    }
                    if (userId.equals(createId)) {
                        System.err.println("登录人:" + userId + ",角色是 国家业务员------本人创建");
                        buildingData.setFlag("2");
                    } else if (groupLeaderId.equals(userId)) {
                        System.err.println("登录人:" + userId + ",角色是 国家业务员------组长");
                        buildingData.setFlag("2");
                    } else {
                        System.err.println("登录人:" + userId + ",角色是 国家业务员------");
                        buildingData.setFlag("1");
                    }
                    //任务管理员
                    if (taskCodeList.contains(buildingData.getTaskCode())) {
                        buildingData.setFlag("2");
                    }
                    list.add(buildingData);
                }
            }
            return list;
        }
        //省级管理员(各省查看各省的)  查看  修改  删除
        else if (allRole.contains(FxfzConstants.YPG_PRI_GL_ROLE)) {
            System.err.println("登录人:" + userId + ",角色是 省级管理员------");
            //获取该省所有数据和管理员参与的
            List<BuildingParams> buildingParams = buildingReqository.queryBuildingDataByProvince(userId, provinceId, taskCodeList);
            List<BuildingParams> list = new ArrayList<>();
            if (buildingParams != null && buildingParams.size() > 0) {
                for (BuildingParams buildingData : buildingParams) {
                    //判断该业务员参与的其他省的  是否为组员
                    List<Map<String, Object>> teamMembers = fieldSurveyTaskService.getTeamMembers(buildingData.getTaskCode());//组员
                    if (!PlatformObjectUtils.isEmpty(teamMembers) && teamMembers.size() > 0) {
                        for (Map<String, Object> map2 : teamMembers) {
                            String teamMember = map2.get("user_id").toString();
                            if (!PlatformObjectUtils.isEmpty(teamMember)) {
                                if (userId.equals(teamMember)) {
                                    System.err.println("登录人:" + userId + ",任务编号:" + buildingData.getTaskCode() + ",该任务中的组员------");
                                    buildingData.setFlag("1");
                                    break;
                                }
                            }
                        }
                    }
                    //判断该业务员参与的其他省的    或者自己参与的是否为组长或本人
                    String createId = buildingData.getCreateId();
                    String groupLeaderId = fieldSurveyTaskService.getGroupLeaderId(buildingData.getTaskCode());//组长
                    if (PlatformObjectUtils.isEmpty(groupLeaderId)) {
                        groupLeaderId = "无组长";
                    }
                    if (userId.equals(createId) || userId.equals(groupLeaderId)) {
                        buildingData.setFlag("2");
                    }
                    //判断是否为自己省
                    if (buildingData.getProvinceId() != null && buildingData.getProvinceId().equals(provinceId)) {
                        buildingData.setFlag("2");
                    }
                    //任务管理员
                    if (taskCodeList.contains(buildingData.getTaskCode())) {
                        buildingData.setFlag("2");
                    }
                    list.add(buildingData);
                }
            }
            return list;
        }
        //省级业务员(各省查看各省的)查看   如果是本人创建的或者组长需要加修改删除)
        else if (allRole.contains(FxfzConstants.YPG_PRI_YW_ROLE)) {
            System.err.println("登录人:" + userId + ",角色是 省级业务员------");
            //获取该省所有数据和业务员参与的
            List<BuildingParams> buildingParams = buildingReqository.queryBuildingDataByProvince(userId, provinceId, taskCodeList);
            List<BuildingParams> list = new ArrayList<>();
            if (buildingParams != null && buildingParams.size() > 0) {
                for (BuildingParams buildingData : buildingParams) {
                    //判断是否为自己省
                    if (buildingData.getProvinceId() != null && buildingData.getProvinceId().equals(provinceId)) {
                        buildingData.setFlag("1");
                    }
                    //判断该业务员参与的其他省的  是否为组员
                    List<Map<String, Object>> teamMembers = fieldSurveyTaskService.getTeamMembers(buildingData.getTaskCode());//组员
                    if (!PlatformObjectUtils.isEmpty(teamMembers) && teamMembers.size() > 0) {
                        for (Map<String, Object> map2 : teamMembers) {
                            String teamMember = map2.get("user_id").toString();
                            if (!PlatformObjectUtils.isEmpty(teamMember)) {
                                if (userId.equals(teamMember)) {
                                    System.err.println("登录人:" + userId + ",任务编号:" + buildingData.getTaskCode() + ",该任务中的组员------");
                                    buildingData.setFlag("1");
                                    break;
                                }
                            }
                        }
                    }
                    //判断该业务员参与的其他省的    或者自己参与的是否为组长或本人
                    String createId = buildingData.getCreateId();
                    String groupLeaderId = fieldSurveyTaskService.getGroupLeaderId(buildingData.getTaskCode());//组长
                    if (PlatformObjectUtils.isEmpty(groupLeaderId)) {
                        groupLeaderId = "无组长";
                    }
                    if (userId.equals(createId) || userId.equals(groupLeaderId)) {
                        System.err.println("登录人:" + userId + ",本人创建或者组长------");
                        buildingData.setFlag("2");
                    }
                    //任务管理员
                    if (taskCodeList.contains(buildingData.getTaskCode())) {
                        buildingData.setFlag("2");
                    }
                    list.add(buildingData);
                }
            }
            return list;
        }
        //本人创建的或者组长:查看 修改 删除,或者是小组组员:查看
        System.err.println("登录人:" + userId + ",无国家/省角色------");
        List<BuildingParams> buildingParams = buildingReqository.getBuildingDataByTeamMembers(userId, taskCodeList);
        List<BuildingParams> list = new ArrayList<>();
        if (buildingParams != null && buildingParams.size() > 0) {
            for (BuildingParams buildingData : buildingParams) {
                //获取某任务下所有组员
                List<Map<String, Object>> teamMembers = fieldSurveyTaskService.getTeamMembers(buildingData.getTaskCode());//组员
                if (!PlatformObjectUtils.isEmpty(teamMembers) && teamMembers.size() > 0) {
                    for (Map<String, Object> map2 : teamMembers) {
                        String teamMember = map2.get("user_id").toString();
                        if (!PlatformObjectUtils.isEmpty(teamMember)) {
                            if (userId.equals(teamMember)) {
                                System.err.println("登录人:" + userId + ",任务编号:" + buildingData.getTaskCode() + ",该任务中的组员------");
                                buildingData.setFlag("1");
                                break;
                            }
                        }
                    }
                }
                String groupLeaderId = fieldSurveyTaskService.getGroupLeaderId(buildingData.getTaskCode());//组长
                if (PlatformObjectUtils.isEmpty(groupLeaderId)) {
                    groupLeaderId = "无组长";
                }
                //本人或者组长
                if (userId.equals(buildingData.getCreateId()) || userId.equals(groupLeaderId)) {
                    System.err.println("登录人:" + userId + ",本人创建或者组长------");
                    buildingData.setFlag("2");
                }
                list.add(buildingData);
            }
        }
        return list;
    }

    @Override
    public Map<String, Object> uploadBuilding(MultipartFile file) throws Exception {
        Map<String, Object> map = new HashMap<>();
        boolean res = true;
        try {
            Workbook workBook = WorkbookFactory.create(file.getInputStream());

            if (PlatformObjectUtils.isEmpty(workBook.getSheet("高层建筑"))){
                throw new ServiceException("所导入的建筑结构不存在高层建筑");
            }
            if (PlatformObjectUtils.isEmpty(workBook.getSheet("钢结构"))){
                throw new ServiceException("所导入的建筑结构不存在钢结构");
            }
            if (PlatformObjectUtils.isEmpty(workBook.getSheet("多层钢筋混凝土结构"))){
                throw new ServiceException("所导入的建筑结构不存在多层钢筋混凝土结构");
            }
            if (PlatformObjectUtils.isEmpty(workBook.getSheet("砖混结构"))){
                throw new ServiceException("所导入的建筑结构不存在砖混结构");
            }
            if (PlatformObjectUtils.isEmpty(workBook.getSheet("砖木结构"))){
                throw new ServiceException("所导入的建筑结构不存在砖木结构");
            }
            if (PlatformObjectUtils.isEmpty(workBook.getSheet("土结构"))){
                throw new ServiceException("所导入的建筑结构不存在土结构");
            }
            if (PlatformObjectUtils.isEmpty(workBook.getSheet("木结构"))){
                throw new ServiceException("所导入的建筑结构不存在木结构");
            }
            if (PlatformObjectUtils.isEmpty(workBook.getSheet("石结构"))){
                throw new ServiceException("所导入的建筑结构不存在石结构");
            }
            if (PlatformObjectUtils.isEmpty(workBook.getSheet("其他结构"))){
                throw new ServiceException("所导入的建筑结构不存在其他结构");
            }
            ImportParams params = new ImportParams();
            String userId = PlatformSessionContext.getUserID();
            String user = sUserService.getSUser(userId);
            SUser sUser = CreateGson.createGson().fromJson(user, SUser.class);
            String userName = sUser.getUserName();
            Date date = new Date();
            for (int numSheet = 0; numSheet < workBook.getNumberOfSheets(); numSheet++) {
                params.setTitleRows(0);
                params.setHeadRows(1);
                params.setNeedVerify(true);
                params.setVerifyHandler(buildingExcelVerifyHandler);
                params.setStartSheetIndex(numSheet);
                workBook.getSheetName(numSheet);
                res = false;
                ExcelImportResult<BuildingEntity> result = ExcelImportUtil.importExcelMore(file.getInputStream(), BuildingEntity.class, params);
                List<BuildingEntity> failList = result.getFailList();
                if (PlatformObjectUtils.isNotEmpty(failList)) {
                    StringBuilder errorMsg = new StringBuilder("<font size='5px' color='red'>导入失败请修改后重新导入</font><br>");
                    errorMsg.append("<font size='4px' color='red'>导入失败原因:</font>");
                    for (BuildingEntity buildingEntity : failList) {
                        errorMsg.append("<font size='4px' ><br>" + workBook.getSheetName(numSheet) + "sheet页-").append("第").append(buildingEntity.getRowNum() + 1).append("行： ").append(buildingEntity.getErrorMsg()).append("</font><br>");
                    }
                    map.put("res", res);
                    map.put("mess", errorMsg);
                    return map;
                }
                List<BuildingEntity> resultData = result.getList();
                if (PlatformObjectUtils.isNotEmpty(resultData)) {
                    List<BuildingEntity> list = new ArrayList<>();
                    int excelReadRowIndex = 1;
                    for (BuildingEntity buildingEntity : resultData) {
                        //空行跳过
                        if (PlatformObjectUtils.isEmpty(buildingEntity.getTaskCode()) && PlatformObjectUtils.isEmpty(buildingEntity.getProvince()) && PlatformObjectUtils.isEmpty(buildingEntity.getCity()) && PlatformObjectUtils.isEmpty(buildingEntity.getCounty()) && PlatformObjectUtils.isEmpty(buildingEntity.getCountry()) && PlatformObjectUtils.isEmpty(buildingEntity.getLongitude()) && PlatformObjectUtils.isEmpty(buildingEntity.getLatitude())
                                && PlatformObjectUtils.isEmpty(buildingEntity.getIntensity()) && PlatformObjectUtils.isEmpty(buildingEntity.getBuildYears()) && PlatformObjectUtils.isEmpty(buildingEntity.getPurpose()) && PlatformObjectUtils.isEmpty(buildingEntity.getLayerNum()) && PlatformObjectUtils.isEmpty(buildingEntity.getHeight()) && PlatformObjectUtils.isEmpty(buildingEntity.getTerrainConditions()) && PlatformObjectUtils.isEmpty(buildingEntity.getFoundationCondition())
                                && PlatformObjectUtils.isEmpty(buildingEntity.getPlanarRule()) && PlatformObjectUtils.isEmpty(buildingEntity.getVerticalRule()) && PlatformObjectUtils.isEmpty(buildingEntity.getRoofComponent()) && PlatformObjectUtils.isEmpty(buildingEntity.getHousingCondition()) && PlatformObjectUtils.isEmpty(buildingEntity.getDegreeDescription()) && PlatformObjectUtils.isEmpty(buildingEntity.getSeismicCapacity()) && PlatformObjectUtils.isEmpty(buildingEntity.getRemarks())) {
                            continue;
                        }
                        log.debug("导入数据:{}", JSONObject.toJSONString(buildingEntity, SerializerFeature.PrettyFormat));
                        String uuid = UUIDGenerator.getUUID();
                        buildingEntity.setId(uuid);
                        buildingEntity.setTaskName(fieldSurveyTaskService.getTaskNameByTaskNum(buildingEntity.getTaskCode()));
                        String divisionIds = sysAreaService.getIdByCondition(URLEncoder.encode(buildingEntity.getProvince().trim(), "UTF-8"), URLEncoder.encode(buildingEntity.getCity().trim(), "UTF-8"), URLEncoder.encode(buildingEntity.getCounty().trim(), "UTF-8"));
                        if (StringUtils.isBlank(divisionIds)) {
                            throw new ServiceException("第" + excelReadRowIndex + "行的建筑地点-省(" + buildingEntity.getProvince().trim() + ")有误，请填写准确的名称，例如：北京市");
                        }
                        buildingEntity.setProvinceId(divisionIds.split("_")[0]);
                        if (divisionIds.split("_").length == 1) {
                            throw new ServiceException("第" + excelReadRowIndex + "行的建筑地点-市(" + buildingEntity.getCity().trim() + ")有误，请填写准确的名称，例如：北京市");
                        }
                        buildingEntity.setCityId(divisionIds.split("_")[1]);
                        if (divisionIds.split("_").length == 2) {
                            throw new ServiceException("第" + excelReadRowIndex + "行的建筑地点-县(" + buildingEntity.getCounty().trim() + ")有误，请填写准确的名称，例如：海淀区");
                        }
                        buildingEntity.setCountyId(divisionIds.split("_")[2]);
                        //建筑物编号
                        buildingEntity.setBuildCode(DivisionCache.getSerialNum(divisionIds.split("_")[2]));
                        //sheet页名称就是建筑结构
                        String buildingStructure = workBook.getSheetName(numSheet);
                        verifyRequireData(buildingStructure, buildingEntity, excelReadRowIndex);
                        if (buildingStructure.equals("高层建筑")) {
                            buildingEntity.setBuildingStructure(BuildingStructureConstants.HIGH_STRUCTURE);
                        } else if (buildingStructure.equals("钢结构")) {
                            buildingEntity.setBuildingStructure(BuildingStructureConstants.STEEL_STRUCTURE);
                        } else if (buildingStructure.equals("多层钢筋混凝土结构")) {
                            buildingEntity.setBuildingStructure(BuildingStructureConstants.HNT_STRUCTURE);
                        } else if (buildingStructure.equals("砖混结构")) {
                            buildingEntity.setBuildingStructure(BuildingStructureConstants.ZH_STRUCTURE);
                        } else if (buildingStructure.equals("砖木结构")) {
                            buildingEntity.setBuildingStructure(BuildingStructureConstants.ZM_STRUCTURE);
                        } else if (buildingStructure.equals("土结构")) {
                            buildingEntity.setBuildingStructure(BuildingStructureConstants.SOIL_STRUCTURE);
                        } else if (buildingStructure.equals("木结构")) {
                            buildingEntity.setBuildingStructure(BuildingStructureConstants.WOOD_STRUCTURE);
                        } else if (buildingStructure.equals("石结构")) {
                            buildingEntity.setBuildingStructure(BuildingStructureConstants.STONE_STRUCTURE);
                        } else if (buildingStructure.equals("其他结构")) {
                            buildingEntity.setBuildingStructure(BuildingStructureConstants.OTHER_STRUCTURE);
                        }

                        String fieldSurveyId = samplingReqository.getFieldSurveyId(buildingEntity.getTaskCode(), buildingEntity.getFieldSurveyName().trim());
                        buildingEntity.setFieldSurveyId(fieldSurveyId);
                        buildingEntity.setIsSubmit("1");
                        buildingEntity.setDelFlag("0");
                        buildingEntity.setCreateName(userName);
                        buildingEntity.setCreateId(userId);
                        buildingEntity.setCreateTime(date);
                        buildingEntity.setSubmitter(userName);
                        buildingEntity.setSubmitterId(userId);
                        buildingEntity.setSubmitTime(date);
                        String longitude = buildingEntity.getLongitude();
                        String latitude = buildingEntity.getLatitude();
                        String geom = "POINT(" + longitude + " " + latitude + ")";
                        buildingEntity.setGeom(geom);
                        list.add(buildingEntity);
                        excelReadRowIndex++;
                    }
                    if (!PlatformObjectUtils.isEmpty(list)) {
                        for (BuildingEntity buildingEntity : list) {
                            res = buildingReqository.saveBuilding(buildingEntity);
                            if (!res) {
                                break;
                            }
                        }
                    }
                }
            }
        } catch (Exception e) {
//            e.printStackTrace();
            log.error("导入失败");
            throw e;
        }
        map.put("res", true);
        return map;
    }

    private void verifyRequireData(String sheetName, BuildingEntity buildingEntity, Integer currRow) throws ServiceException {
        if (sheetName.equals("高层建筑")) {
            if (ObjectUtils.isEmpty(buildingEntity.getHighStructureType())) {
                throw new ServiceException("第" + currRow + "行的 高层建筑-结构类型不能为空");
            }
        } else if (sheetName.equals("钢结构")) {
            if (ObjectUtils.isEmpty(buildingEntity.getSteelStructureType())) {
                throw new ServiceException("第" + currRow + "行的 钢结构-结构类型不能为空");
            }
        } else if (sheetName.equals("多层钢筋混凝土结构")) {
            if (ObjectUtils.isEmpty(buildingEntity.getHntConnectionType())) {
                throw new ServiceException("第" + currRow + "行的 填充墙与柱连接方式不能为空");
            }
            if (ObjectUtils.isEmpty(buildingEntity.getHntStairsPosition())) {
                throw new ServiceException("第" + currRow + "行的 楼梯间位置（是否在近端或转角）不能为空");
            }
            if (ObjectUtils.isEmpty(buildingEntity.getHntColumnSectionSize())) {
                throw new ServiceException("第" + currRow + "行的 主要柱截面尺寸不能为空");
            }
            if (ObjectUtils.isEmpty(buildingEntity.getHntBeamSectionSize())) {
                throw new ServiceException("第" + currRow + "行的 主要梁截面尺寸不能为空");
            }
            if (ObjectUtils.isEmpty(buildingEntity.getHntWeakLink())) {
                throw new ServiceException("第" + currRow + "行的 薄弱环节不能为空");
            }
            if (ObjectUtils.isEmpty(buildingEntity.getHntMaxColumnCpacing())) {
                throw new ServiceException("第" + currRow + "行的 最大柱间距不能为空");
            }
            if (ObjectUtils.isEmpty(buildingEntity.getHntMaximumFloorHeight())) {
                throw new ServiceException("第" + currRow + "行的 最大层高不能为空");
            }
            if (ObjectUtils.isEmpty(buildingEntity.getHntMaxSpanSeam())) {
                throw new ServiceException("第" + currRow + "行的 梁最大跨度不能为空");
            }
        } else if (sheetName.equals("砖混结构")) {
            if (ObjectUtils.isEmpty(buildingEntity.getZhFloorType())) {
                throw new ServiceException("第" + currRow + "行的 楼盖类型不能为空");
            }
            if (ObjectUtils.isEmpty(buildingEntity.getZhRoofType())) {
                throw new ServiceException("第" + currRow + "行的 砖混结构-屋盖类型不能为空");
            }
            if (ObjectUtils.isEmpty(buildingEntity.getZhWallMaterials())) {
                throw new ServiceException("第" + currRow + "行的 砖混结构-墙体材料不能为空");
            }
            if (ObjectUtils.isEmpty(buildingEntity.getZhWallThicknessInterior())) {
                throw new ServiceException("第" + currRow + "行的 墙体厚度-内墙不能为空");
            }
            if (ObjectUtils.isEmpty(buildingEntity.getZhWallThicknessExterior())) {
                throw new ServiceException("第" + currRow + "行的 墙体厚度-外墙不能为空");
            }
            if (ObjectUtils.isEmpty(buildingEntity.getZhMortarType())) {
                throw new ServiceException("第" + currRow + "行的 砂浆类别不能为空");
            }
            if (ObjectUtils.isEmpty(buildingEntity.getZhMortarStrength())) {
                throw new ServiceException("第" + currRow + "行的 砂浆强度不能为空");
            }
            if (ObjectUtils.isEmpty(buildingEntity.getZhBearingSystem())) {
                throw new ServiceException("第" + currRow + "行的 承重体系不能为空");
            }
            if (ObjectUtils.isEmpty(buildingEntity.getZhBearingMode())) {
                throw new ServiceException("第" + currRow + "行的 承重墙砌筑方式不能为空");
            }
            if (ObjectUtils.isEmpty(buildingEntity.getZhStaircaseLocation())) {
                throw new ServiceException("第" + currRow + "行的 楼梯间位置（是否在近端或转角）不能为空");
            }
            if (ObjectUtils.isEmpty(buildingEntity.getZhHoleCrner())) {
                throw new ServiceException("第" + currRow + "行的 大洞窗,转角窗不能为空");
            }
            if (ObjectUtils.isEmpty(buildingEntity.getZhStructuralColumn())) {
                throw new ServiceException("第" + currRow + "行的 砖混结构-构造柱不能为空");
            }
            if (ObjectUtils.isEmpty(buildingEntity.getZhRingBeam())) {
                throw new ServiceException("第" + currRow + "行的 砖混结构-圈梁不能为空");
            }
        } else if (sheetName.equals("砖木结构")) {
            if (ObjectUtils.isEmpty(buildingEntity.getZmRoofType())) {
                throw new ServiceException("第" + currRow + "行的 砖木结构-屋盖类型不能为空");
            }
            if (ObjectUtils.isEmpty(buildingEntity.getZmWallMaterials())) {
                throw new ServiceException("第" + currRow + "行的 砖木结构-墙体材料不能为空");
            }
            if (ObjectUtils.isEmpty(buildingEntity.getZmMortar())) {
                throw new ServiceException("第" + currRow + "行的 砂浆不能为空");
            }
            if (ObjectUtils.isEmpty(buildingEntity.getZmBearingSystem())) {
                throw new ServiceException("第" + currRow + "行的 承重体系不能为空");
            }
            if (ObjectUtils.isEmpty(buildingEntity.getZmWallOpeningArea())) {
                throw new ServiceException("第" + currRow + "行的 横墙开洞面积（水平全截面面积1/3）不能为空");
            }
            if (ObjectUtils.isEmpty(buildingEntity.getZmStructuralColumn())) {
                throw new ServiceException("第" + currRow + "行的 砖木结构-构造柱不能为空");
            }
            if (ObjectUtils.isEmpty(buildingEntity.getZmRingBeam())) {
                throw new ServiceException("第" + currRow + "行的 砖木结构-圈梁不能为空");
            }
        } else if (sheetName.equals("土结构")) {
            if (ObjectUtils.isEmpty(buildingEntity.getSoilHardMountain())) {
                throw new ServiceException("第" + currRow + "行的 硬山搁檀不能为空");
            }
            if (ObjectUtils.isEmpty(buildingEntity.getSoilWall())) {
                throw new ServiceException("第" + currRow + "行的 墙体不能为空");
            }
            if (ObjectUtils.isEmpty(buildingEntity.getSoilModeType())) {
                throw new ServiceException("第" + currRow + "行的 墙体建筑方式不能为空");
            }
            if (ObjectUtils.isEmpty(buildingEntity.getSoilWallRingBeam())) {
                throw new ServiceException("第" + currRow + "行的 有无墙体圈梁不能为空");
            }
            if (ObjectUtils.isEmpty(buildingEntity.getSoilWallDuctileMaterial())) {
                throw new ServiceException("第" + currRow + "行的 墙体延性材料不能为空");
            }
            if (ObjectUtils.isEmpty(buildingEntity.getSoilDoorWindowWidth())) {
                throw new ServiceException("第" + currRow + "行的 门窗洞口宽度不能为空");
            }
            if (ObjectUtils.isEmpty(buildingEntity.getSoilMaxSpacing())) {
                throw new ServiceException("第" + currRow + "行的 承重墙最大间距不能为空");
            }
            if (ObjectUtils.isEmpty(buildingEntity.getSoilRoofForm())) {
                throw new ServiceException("第" + currRow + "行的 屋面形式不能为空");
            }
            if (ObjectUtils.isEmpty(buildingEntity.getSoilRoofingMaterials())) {
                throw new ServiceException("第" + currRow + "行的 屋面材料不能为空");
            }
            if (ObjectUtils.isEmpty(buildingEntity.getSoilRoofTyingMeasures())) {
                throw new ServiceException("第" + currRow + "行的 屋楼盖拉结措施不能为空");
            }
        } else if (sheetName.equals("木结构")) {
            if (ObjectUtils.isEmpty(buildingEntity.getWoodStructureType())) {
                throw new ServiceException("第" + currRow + "行的 结构类型措施不能为空");
            }
            if (ObjectUtils.isEmpty(buildingEntity.getWoodColumnsBracing())) {
                throw new ServiceException("第" + currRow + "行的 柱间支撑不能为空");
            }
            if (ObjectUtils.isEmpty(buildingEntity.getWoodColumnExtension())) {
                throw new ServiceException("第" + currRow + "行的 木柱接长处接榫是否牢固不能为空");
            }
            if (ObjectUtils.isEmpty(buildingEntity.getWoodNode())) {
                throw new ServiceException("第" + currRow + "行的 节点不能为空");
            }
            if (ObjectUtils.isEmpty(buildingEntity.getWoodTipDiameter())) {
                throw new ServiceException("第" + currRow + "行的 木径梢径不能为空");
            }
            if (ObjectUtils.isEmpty(buildingEntity.getWoodFoundationAnchoring())) {
                throw new ServiceException("第" + currRow + "行的 柱脚与基础锚固不能为空");
            }
            if (ObjectUtils.isEmpty(buildingEntity.getWoodGableWall())) {
                throw new ServiceException("第" + currRow + "行的 山尖墙不能为空");
            }
            if (ObjectUtils.isEmpty(buildingEntity.getWoodEnclosureWall())) {
                throw new ServiceException("第" + currRow + "行的 围护墙不能为空");
            }
            if (ObjectUtils.isEmpty(buildingEntity.getWoodWallConnection())) {
                throw new ServiceException("第" + currRow + "行的 墙体连接不能为空");
            }
        } else if (sheetName.equals("石结构")) {
            if (ObjectUtils.isEmpty(buildingEntity.getStoneWallMaterials())) {
                throw new ServiceException("第" + currRow + "行的 石结构-墙体材料不能为空");
            }
            if (ObjectUtils.isEmpty(buildingEntity.getStoneLoadMode())) {
                throw new ServiceException("第" + currRow + "行的 承重方式不能为空");
            }
            if (ObjectUtils.isEmpty(buildingEntity.getStoneFloorStructure())) {
                throw new ServiceException("第" + currRow + "行的 上下楼层结构类型不能为空");
            }
            if (ObjectUtils.isEmpty(buildingEntity.getStoneRoofType())) {
                throw new ServiceException("第" + currRow + "行的 楼屋盖类型不能为空");
            }
            if (ObjectUtils.isEmpty(buildingEntity.getStoneMaximumSpacing())) {
                throw new ServiceException("第" + currRow + "行的 横墙最大间距不能为空");
            }
            if (ObjectUtils.isEmpty(buildingEntity.getStoneWallOpeningArea())) {
                throw new ServiceException("第" + currRow + "行的 横墙开洞面积大于或小于水平全截面面积1/3不能为空");
            }
            if (ObjectUtils.isEmpty(buildingEntity.getStoneWallConnection())) {
                throw new ServiceException("第" + currRow + "行的 纵横墙连接不能为空");
            }
            if (ObjectUtils.isEmpty(buildingEntity.getStoneRingBeam())) {
                throw new ServiceException("第" + currRow + "行的 石结构-圈梁不能为空");
            }
            if (ObjectUtils.isEmpty(buildingEntity.getStoneFourStructural())) {
                throw new ServiceException("第" + currRow + "行的 四角构造柱不能为空");
            }
        } else if (sheetName.equals("其他结构")) {
        }
    }

//    @Override
//    public void exportBuilding(HttpServletResponse response, BuildingParams queryParams) throws IOException {
//        String userId = PlatformSessionContext.getUserID();
//        String user = sUserService.getSUser(userId);
//        SUser sUser = CreateGson.createGson().fromJson(user, SUser.class);
//        String role = sysRoleService.getRoleByUserId(userId);
//        List<Map> maps = JSONObject.parseArray(role, Map.class);//一个人可能有多个角色
//        //当前登录人所有的角色
//        StringBuilder roles = new StringBuilder();
//        for (int i = 0; i < maps.size(); i++) {
//            Map map = maps.get(i);
//            roles.append(map.get("roleCode") + ",");
//        }
//        String allRole = roles.toString();
//        String provinceId = sUser.getProvinceId();//省id
//        //获取所有任务编号和任务管理员
//        List<TaskVo> taskManagers = fieldSurveyTaskService.getTaskManagers();
//        //当前登录人(任务管理员)新建的所有任务
//        List<String> taskCodeList = new ArrayList<>();
//        //boolean flag = false;
//        for (TaskVo taskVo : taskManagers) {
//            String createUser = taskVo.getCreateUser();
//            if (createUser.equals(userId)) {
//                taskCodeList.add(taskVo.getTaskNum());
//            }
//        }
//        List<BuildingEntity> buildingEntities = null;
//        if (allRole.contains(FxfzConstants.YPG_COUN_GL_ROLE)) {
//            buildingEntities = buildingReqository.queryBuilding(queryParams);
//        }
//
//        //国家业务员  查看 (如果是本人创建的或者组长需要加修改删除)
//        else if (allRole.contains(FxfzConstants.YPG_COUN_YW_ROLE)) {
//            buildingEntities = buildingReqository.queryBuilding(queryParams);
//
//        }
//        //省级管理员(各省查看各省的)  查看  修改  删除
//        else if (allRole.contains(FxfzConstants.YPG_PRI_GL_ROLE)) {
//            buildingEntities = buildingReqository.queryBuildingByProvince(queryParams, userId, provinceId, taskCodeList);
//
//        }
//        //省级业务员(各省查看各省的)查看   如果是本人创建的或者组长需要加修改删除)
//        else if (allRole.contains(FxfzConstants.YPG_PRI_YW_ROLE)) {
//            buildingEntities = buildingReqository.queryBuildingByProvince(queryParams, userId, provinceId, taskCodeList);
//
//        } else {
//            //无角色 本人
//            buildingEntities = buildingReqository.queryBuildingDataByTeamMembers(queryParams, userId, taskCodeList);
//        }
//
//
//        //-------------------------------建筑物单体导出-----------------------------------
//        List<BuildingEntity> gcList = new ArrayList<>();//高层建筑
//        List<BuildingEntity> gList = new ArrayList<>();//钢结构
//        List<BuildingEntity> dcgjhntList = new ArrayList<>();//多层钢筋混凝土结构
//        List<BuildingEntity> zhList = new ArrayList<>();//砖混结构
//        List<BuildingEntity> zmList = new ArrayList<>();//砖木结构
//        List<BuildingEntity> tList = new ArrayList<>();//土结构
//        List<BuildingEntity> mList = new ArrayList<>();//木结构
//        List<BuildingEntity> sList = new ArrayList<>();//石结构
//        List<BuildingEntity> qtList = new ArrayList<>();//其他结构
//        if (!PlatformObjectUtils.isEmpty(buildingEntities)) {
//            //去重
//            List<BuildingEntity> buildingEntityList = duplicateRemoval(buildingEntities);
//            for (BuildingEntity buildingEntity : buildingEntityList) {
//                if (buildingEntity.getBuildingStructure().equals(BuildingStructureConstants.HIGH_STRUCTURE)) {
//                    buildingEntity.setBuildingStructure("高层建筑");
//                    gcList.add(buildingEntity);
//                } else if (buildingEntity.getBuildingStructure().equals(BuildingStructureConstants.STEEL_STRUCTURE)) {
//                    buildingEntity.setBuildingStructure("钢结构");
//                    gList.add(buildingEntity);
//                } else if (buildingEntity.getBuildingStructure().equals(BuildingStructureConstants.HNT_STRUCTURE)) {
//                    buildingEntity.setBuildingStructure("多层钢筋混凝土结构");
//                    dcgjhntList.add(buildingEntity);
//                } else if (buildingEntity.getBuildingStructure().equals(BuildingStructureConstants.ZH_STRUCTURE)) {
//                    buildingEntity.setBuildingStructure("砖混结构");
//                    zhList.add(buildingEntity);
//                } else if (buildingEntity.getBuildingStructure().equals(BuildingStructureConstants.ZM_STRUCTURE)) {
//                    buildingEntity.setBuildingStructure("砖木结构");
//                    zmList.add(buildingEntity);
//                } else if (buildingEntity.getBuildingStructure().equals(BuildingStructureConstants.SOIL_STRUCTURE)) {
//                    buildingEntity.setBuildingStructure("土结构");
//                    tList.add(buildingEntity);
//                } else if (buildingEntity.getBuildingStructure().equals(BuildingStructureConstants.WOOD_STRUCTURE)) {
//                    buildingEntity.setBuildingStructure("木结构");
//                    mList.add(buildingEntity);
//                } else if (buildingEntity.getBuildingStructure().equals(BuildingStructureConstants.STONE_STRUCTURE)) {
//                    buildingEntity.setBuildingStructure("石结构");
//                    sList.add(buildingEntity);
//                } else if (buildingEntity.getBuildingStructure().equals(BuildingStructureConstants.OTHER_STRUCTURE)) {
//                    buildingEntity.setBuildingStructure("其他结构");
//                    qtList.add(buildingEntity);
//                }
//            }
//
//            String name = "建筑物单体数据";
//            response.setContentType("application/octet-stream ");
//            response.setHeader("Connection", "close"); // 表示不能用浏览器直接打开
//            response.setHeader("Accept-Ranges", "bytes");// 告诉客户端允许断点续传多线程连接下载
//            response.setHeader("Content-Disposition",
//                    "attachment;filename=" + new String(name.getBytes("GB2312"), "ISO8859-1"));
//            response.setCharacterEncoding("UTF-8");
//            OutputStream out = response.getOutputStream();
//            HSSFWorkbook workbook = new HSSFWorkbook();
//
//            // 样式设置
//            HSSFCellStyle columnHeadStyle = workbook.createCellStyle();
//            columnHeadStyle.setFillPattern(FillPatternType.NO_FILL); // 背景
//            columnHeadStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex()); // 背景色AQUA.getIndex()
//            columnHeadStyle.setBorderBottom(BorderStyle.THIN); // 下边框
//            columnHeadStyle.setBorderLeft(BorderStyle.THIN);// 左边框
//            columnHeadStyle.setBorderTop(BorderStyle.THIN);// 上边框
//            columnHeadStyle.setBorderRight(BorderStyle.THIN);// 右边框
//            columnHeadStyle.setAlignment(HorizontalAlignment.CENTER);//水平居中
//            columnHeadStyle.setVerticalAlignment(VerticalAlignment.CENTER);// 上下居中
//            columnHeadStyle.setWrapText(true);//自动换行
//            HSSFFont headFont = workbook.createFont();
//            headFont.setFontName("黑体");
//            headFont.setFontHeightInPoints((short) 12);// 字体大小
//            columnHeadStyle.setFont(headFont);
//            // 全局样式设置
//            HSSFCellStyle allStyle = workbook.createCellStyle();
//            allStyle.setFillPattern(FillPatternType.NO_FILL); // 背景
//            allStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex());// 填充白色
//            allStyle.setBorderBottom(BorderStyle.THIN); // 下边框
//            allStyle.setBorderLeft(BorderStyle.THIN);// 左边框
//            allStyle.setBorderTop(BorderStyle.THIN);// 上边框
//            allStyle.setBorderRight(BorderStyle.THIN);// 右边框
//            allStyle.setAlignment(HorizontalAlignment.CENTER);//水平居中
//            allStyle.setVerticalAlignment(VerticalAlignment.CENTER);// 上下居中
//            allStyle.setWrapText(true);//自动换行
//
//            HSSFSheet sheet0 = workbook.createSheet("高层建筑");
//            String[] sheet0HeadTitle = {"任务编号", "建筑编号", "建筑地点-省", "建筑地点-市", "建筑地点-县", "建筑地点-乡", "经度", "纬度", "设防烈度", "建造年代", "用途", "层数", "高度（m）", "地形条件（有无山体滑坡、山崩危险）", "地基情况（有无下部软弱土层）", "平面型规则", "竖向规则性", "出屋面构件", "房屋状况", "程度描述", "抗震能力", "备注", "建筑结构", "高层建筑-结构类型"};
//            for (int k = 0; k <= gcList.size(); k++) {
//                HSSFRow rowk = sheet0.createRow(k);
//                rowk.setHeightInPoints((short) 30);
//                //rowk.setHeight((short) 600);
//                for (int i = 0; i < sheet0HeadTitle.length; i++) {
//                    if (k == 0) {
//                        HSSFCell cel1_i = rowk.createCell(i);
//                        cel1_i.setCellValue(new HSSFRichTextString(sheet0HeadTitle[i]));
//                        cel1_i.setCellStyle(columnHeadStyle);
//                    } else {
//                        GcExcelVo gcExcelVo = new GcExcelVo();
//                        SpringUtil.copyPropertiesIgnoreNull(gcList.get(k - 1), gcExcelVo);
//                        String[] gcValues = PoiExcelUtil.objectChangeArray(gcExcelVo);
//                        HSSFCell celk_i = rowk.createCell(i);
//                        if (!PlatformObjectUtils.isEmpty(gcValues[i])) {
//                            celk_i.setCellValue(new HSSFRichTextString(gcValues[i]));
//                            celk_i.setCellStyle(allStyle);
//                        } else {
//                            celk_i.setCellStyle(allStyle);
//                        }
//                    }
//                    sheet0.autoSizeColumn((short) i);
//                }
//            }
//
//            HSSFSheet sheet1 = workbook.createSheet("钢结构");
//            String[] sheet1HeadTitle = {"任务编号", "建筑编号", "建筑地点-省", "建筑地点-市", "建筑地点-县", "建筑地点-乡", "经度", "纬度", "设防烈度", "建造年代", "用途", "层数", "高度（m）", "地形条件（有无山体滑坡、山崩危险）", "地基情况（有无下部软弱土层）", "平面型规则", "竖向规则性", "出屋面构件", "房屋状况", "程度描述", "抗震能力", "备注", "建筑结构", "钢结构-结构类型"};
//            for (int k = 0; k <= gList.size(); k++) {
//                HSSFRow rowk = sheet1.createRow(k);
//                rowk.setHeightInPoints(30);
//                for (int i = 0; i < sheet1HeadTitle.length; i++) {
//                    if (k == 0) {
//                        HSSFCell cel1_i = rowk.createCell(i);
//                        cel1_i.setCellValue(new HSSFRichTextString(sheet1HeadTitle[i]));
//                        cel1_i.setCellStyle(columnHeadStyle);
//                    } else {
//                        GExcelVo gExcelVo = new GExcelVo();
//                        SpringUtil.copyPropertiesIgnoreNull(gList.get(k - 1), gExcelVo);
//                        String[] gValues = PoiExcelUtil.objectChangeArray(gExcelVo);
//                        HSSFCell celk_i = rowk.createCell(i);
//                        if (!PlatformObjectUtils.isEmpty(gValues[i])) {
//                            celk_i.setCellValue(new HSSFRichTextString(gValues[i]));
//                            celk_i.setCellStyle(allStyle);
//                        } else {
//                            celk_i.setCellStyle(allStyle);
//                        }
//                    }
//                    sheet1.autoSizeColumn((short) i);
//                }
//            }
//
//            HSSFSheet sheet2 = workbook.createSheet("多层钢筋混凝土结构");
//            String[] sheet2HeadTitle = {"任务编号", "建筑编号", "建筑地点-省", "建筑地点-市", "建筑地点-县", "建筑地点-乡", "经度", "纬度", "设防烈度", "建造年代", "用途", "层数", "高度（m）", "地形条件（有无山体滑坡、山崩危险）", "地基情况（有无下部软弱土层）", "平面型规则", "竖向规则性", "出屋面构件", "房屋状况", "程度描述", "抗震能力", "备注", "建筑结构", "填充墙与柱连接方式", "楼梯间位置（是否在近端或转角）", "主要柱截面尺寸（mm*mm）", "主要梁截面尺寸（mm*mm）", "薄弱环节", "最大柱间距(m)", "最大层高(m)", "梁最大跨度(m)"};
//            for (int k = 0; k <= dcgjhntList.size(); k++) {
//                HSSFRow rowk = sheet2.createRow(k);
//                rowk.setHeightInPoints(30);
//                for (int i = 0; i < sheet2HeadTitle.length; i++) {
//                    if (k == 0) {
//                        HSSFCell cel1_i = rowk.createCell(i);
//                        cel1_i.setCellValue(new HSSFRichTextString(sheet2HeadTitle[i]));
//                        cel1_i.setCellStyle(columnHeadStyle);
//                    } else {
//                        DcgjhntExcelVo dcgjhntExcelVo = new DcgjhntExcelVo();
//                        SpringUtil.copyPropertiesIgnoreNull(dcgjhntList.get(k - 1), dcgjhntExcelVo);
//                        String[] dcgjhntValues = PoiExcelUtil.objectChangeArray(dcgjhntExcelVo);
//                        HSSFCell celk_i = rowk.createCell(i);
//                        if (!PlatformObjectUtils.isEmpty(dcgjhntValues[i])) {
//                            celk_i.setCellValue(new HSSFRichTextString(dcgjhntValues[i]));
//                            celk_i.setCellStyle(allStyle);
//                        } else {
//                            celk_i.setCellStyle(allStyle);
//                        }
//                    }
//                    sheet2.autoSizeColumn((short) i);
//                }
//            }
//
//            HSSFSheet sheet3 = workbook.createSheet("砖混结构");
//            String[] sheet3HeadTitle = {"任务编号", "建筑编号", "建筑地点-省", "建筑地点-市", "建筑地点-县", "建筑地点-乡", "经度", "纬度", "设防烈度", "建造年代", "用途", "层数", "高度（m）", "地形条件（有无山体滑坡、山崩危险）", "地基情况（有无下部软弱土层）", "平面型规则", "竖向规则性", "出屋面构件", "房屋状况", "程度描述", "抗震能力", "备注", "建筑结构", "楼盖类型", "屋盖类型", "墙体材料", "墙体厚度-内墙（mm）", "墙体厚度-外墙（mm）", "砂浆类别", "砂浆强度", "承重体系", "承重墙砌筑方式", "楼梯间位置（是否在近端或转角）", "大洞窗,转角窗", "构造柱", "圈梁"};
//            for (int k = 0; k <= zhList.size(); k++) {
//                HSSFRow rowk = sheet3.createRow(k);
//                rowk.setHeightInPoints(30);
//                for (int i = 0; i < sheet3HeadTitle.length; i++) {
//                    if (k == 0) {
//                        HSSFCell cel1_i = rowk.createCell(i);
//                        cel1_i.setCellValue(new HSSFRichTextString(sheet3HeadTitle[i]));
//                        cel1_i.setCellStyle(columnHeadStyle);
//                    } else {
//                        ZhExcelVo zhExcelVo = new ZhExcelVo();
//                        SpringUtil.copyPropertiesIgnoreNull(zhList.get(k - 1), zhExcelVo);
//                        String[] zhValues = PoiExcelUtil.objectChangeArray(zhExcelVo);
//                        HSSFCell celk_i = rowk.createCell(i);
//                        if (!PlatformObjectUtils.isEmpty(zhValues[i])) {
//                            celk_i.setCellValue(new HSSFRichTextString(zhValues[i]));
//                            celk_i.setCellStyle(allStyle);
//                        } else {
//                            celk_i.setCellStyle(allStyle);
//                        }
//                    }
//                    sheet3.autoSizeColumn((short) i);
//                }
//            }
//
//            HSSFSheet sheet4 = workbook.createSheet("砖木结构");
//            String[] sheet4HeadTitle = {"任务编号", "建筑编号", "建筑地点-省", "建筑地点-市", "建筑地点-县", "建筑地点-乡", "经度", "纬度", "设防烈度", "建造年代", "用途", "层数", "高度（m）", "地形条件（有无山体滑坡、山崩危险）", "地基情况（有无下部软弱土层）", "平面型规则", "竖向规则性", "出屋面构件", "房屋状况", "程度描述", "抗震能力", "备注", "建筑结构", "屋盖类型", "墙体材料", "砂浆", "承重体系", "横墙开洞面积（水平全截面面积1/3）", "构造柱", "圈梁"};
//            for (int k = 0; k <= zmList.size(); k++) {
//                HSSFRow rowk = sheet4.createRow(k);
//                rowk.setHeightInPoints(30);
//                for (int i = 0; i < sheet4HeadTitle.length; i++) {
//                    if (k == 0) {
//                        HSSFCell cel1_i = rowk.createCell(i);
//                        cel1_i.setCellValue(new HSSFRichTextString(sheet4HeadTitle[i]));
//                        cel1_i.setCellStyle(columnHeadStyle);
//                    } else {
//                        ZmExcelVo zmExcelVo = new ZmExcelVo();
//                        SpringUtil.copyPropertiesIgnoreNull(zmList.get(k - 1), zmExcelVo);
//                        String[] gValues = PoiExcelUtil.objectChangeArray(zmExcelVo);
//                        HSSFCell celk_i = rowk.createCell(i);
//                        if (!PlatformObjectUtils.isEmpty(gValues[i])) {
//                            celk_i.setCellValue(new HSSFRichTextString(gValues[i]));
//                            celk_i.setCellStyle(allStyle);
//                        } else {
//                            celk_i.setCellStyle(allStyle);
//                        }
//                    }
//                    sheet4.autoSizeColumn((short) i);
//                }
//            }
//
//            HSSFSheet sheet5 = workbook.createSheet("土结构");
//            String[] sheet5HeadTitle = {"任务编号", "建筑编号", "建筑地点-省", "建筑地点-市", "建筑地点-县", "建筑地点-乡", "经度", "纬度", "设防烈度", "建造年代", "用途", "层数", "高度（m）", "地形条件（有无山体滑坡、山崩危险）", "地基情况（有无下部软弱土层）", "平面型规则", "竖向规则性", "出屋面构件", "房屋状况", "程度描述", "抗震能力", "备注", "建筑结构", "硬山搁檀", "墙体", "墙体建筑方式", "有无墙体圈梁", "墙体延性材料", "门窗洞口宽度", "承重墙最大间距", "屋面形式", "屋面材料", "屋楼盖拉结措施"};
//            for (int k = 0; k <= tList.size(); k++) {
//                HSSFRow rowk = sheet5.createRow(k);
//                rowk.setHeightInPoints(30);
//                for (int i = 0; i < sheet5HeadTitle.length; i++) {
//                    if (k == 0) {
//                        HSSFCell cel1_i = rowk.createCell(i);
//                        cel1_i.setCellValue(new HSSFRichTextString(sheet5HeadTitle[i]));
//                        cel1_i.setCellStyle(columnHeadStyle);
//                    } else {
//                        TExcelVo tExcelVo = new TExcelVo();
//                        SpringUtil.copyPropertiesIgnoreNull(tList.get(k - 1), tExcelVo);
//                        String[] gValues = PoiExcelUtil.objectChangeArray(tExcelVo);
//                        HSSFCell celk_i = rowk.createCell(i);
//                        if (!PlatformObjectUtils.isEmpty(gValues[i])) {
//                            celk_i.setCellValue(new HSSFRichTextString(gValues[i]));
//                            celk_i.setCellStyle(allStyle);
//                        } else {
//                            celk_i.setCellStyle(allStyle);
//                        }
//                    }
//                    sheet5.autoSizeColumn((short) i);
//                }
//            }
//
//            HSSFSheet sheet6 = workbook.createSheet("木结构");
//            String[] sheet6HeadTitle = {"任务编号", "建筑编号", "建筑地点-省", "建筑地点-市", "建筑地点-县", "建筑地点-乡", "经度", "纬度", "设防烈度", "建造年代", "用途", "层数", "高度（m）", "地形条件（有无山体滑坡、山崩危险）", "地基情况（有无下部软弱土层）", "平面型规则", "竖向规则性", "出屋面构件", "房屋状况", "程度描述", "抗震能力", "备注", "建筑结构", "结构类型", "柱间支撑", "木柱接长处接榫是否牢固", "节点", "木径梢径", "柱脚与基础锚固", "山尖墙", "围护墙", "墙体连接"};
//            for (int k = 0; k <= mList.size(); k++) {
//                HSSFRow rowk = sheet6.createRow(k);
//                rowk.setHeightInPoints(30);
//                for (int i = 0; i < sheet6HeadTitle.length; i++) {
//                    if (k == 0) {
//                        HSSFCell cel1_i = rowk.createCell(i);
//                        cel1_i.setCellValue(new HSSFRichTextString(sheet6HeadTitle[i]));
//                        cel1_i.setCellStyle(columnHeadStyle);
//                    } else {
//                        MExcelVo mExcelVo = new MExcelVo();
//                        SpringUtil.copyPropertiesIgnoreNull(mList.get(k - 1), mExcelVo);
//                        String[] gValues = PoiExcelUtil.objectChangeArray(mExcelVo);
//                        HSSFCell celk_i = rowk.createCell(i);
//                        if (!PlatformObjectUtils.isEmpty(gValues[i])) {
//                            celk_i.setCellValue(new HSSFRichTextString(gValues[i]));
//                            celk_i.setCellStyle(allStyle);
//                        } else {
//                            celk_i.setCellStyle(allStyle);
//                        }
//                    }
//                    sheet6.autoSizeColumn((short) i);
//                }
//            }
//
//            HSSFSheet sheet7 = workbook.createSheet("石结构");
//            String[] sheet7HeadTitle = {"任务编号", "建筑编号", "建筑地点-省", "建筑地点-市", "建筑地点-县", "建筑地点-乡", "经度", "纬度", "设防烈度", "建造年代", "用途", "层数", "高度（m）", "地形条件（有无山体滑坡、山崩危险）", "地基情况（有无下部软弱土层）", "平面型规则", "竖向规则性", "出屋面构件", "房屋状况", "程度描述", "抗震能力", "备注", "建筑结构", "墙体材料", "承重方式", "上下楼层结构类型", "楼屋盖类型", "横墙最大间距（m）", "横墙开洞面积大于或小于水平全截面面积1/3", "纵横墙连接", "圈梁", "四角构造柱"};
//            for (int k = 0; k <= sList.size(); k++) {
//                HSSFRow rowk = sheet7.createRow(k);
//                rowk.setHeightInPoints(30);
//                for (int i = 0; i < sheet7HeadTitle.length; i++) {
//                    if (k == 0) {
//                        HSSFCell cel1_i = rowk.createCell(i);
//                        cel1_i.setCellValue(new HSSFRichTextString(sheet7HeadTitle[i]));
//                        cel1_i.setCellStyle(columnHeadStyle);
//                    } else {
//                        SExcelVo sExcelVo = new SExcelVo();
//                        SpringUtil.copyPropertiesIgnoreNull(sList.get(k - 1), sExcelVo);
//                        String[] gValues = PoiExcelUtil.objectChangeArray(sExcelVo);
//                        HSSFCell celk_i = rowk.createCell(i);
//                        if (!PlatformObjectUtils.isEmpty(gValues[i])) {
//                            celk_i.setCellValue(new HSSFRichTextString(gValues[i]));
//                            celk_i.setCellStyle(allStyle);
//                        } else {
//                            celk_i.setCellStyle(allStyle);
//                        }
//                    }
//                    sheet7.autoSizeColumn((short) i);
//                }
//            }
//
//            HSSFSheet sheet8 = workbook.createSheet("其他结构");
//            String[] sheet8HeadTitle = {"任务编号", "建筑编号", "建筑地点-省", "建筑地点-市", "建筑地点-县", "建筑地点-乡", "经度", "纬度", "设防烈度", "建造年代", "用途", "层数", "高度（m）", "地形条件（有无山体滑坡、山崩危险）", "地基情况（有无下部软弱土层）", "平面型规则", "竖向规则性", "出屋面构件", "房屋状况", "程度描述", "抗震能力", "备注", "建筑结构"};
//            for (int k = 0; k <= qtList.size(); k++) {
//                HSSFRow rowk = sheet8.createRow(k);
//                rowk.setHeightInPoints(30);
//                for (int i = 0; i < sheet8HeadTitle.length; i++) {
//                    if (k == 0) {
//                        HSSFCell cel1_i = rowk.createCell(i);
//                        cel1_i.setCellValue(new HSSFRichTextString(sheet8HeadTitle[i]));
//                        cel1_i.setCellStyle(columnHeadStyle);
//                    } else {
//                        QtExcelVo qtExcelVo = new QtExcelVo();
//                        SpringUtil.copyPropertiesIgnoreNull(qtList.get(k - 1), qtExcelVo);
//                        String[] gValues = PoiExcelUtil.objectChangeArray(qtExcelVo);
//                        HSSFCell celk_i = rowk.createCell(i);
//                        if (!PlatformObjectUtils.isEmpty(gValues[i])) {
//                            celk_i.setCellValue(new HSSFRichTextString(gValues[i]));
//                            celk_i.setCellStyle(allStyle);
//                        } else {
//                            celk_i.setCellStyle(allStyle);
//                        }
//                    }
//                    sheet8.autoSizeColumn((short) i);
//                }
//            }
//            workbook.write(out);
//            if (out != null) {
//                out.flush();
//                out.close();
//            }
//        }
//    }

    private List<BuildingEntity> getBuildingEntity(BuildingParams queryParams){
        String userId = PlatformSessionContext.getUserID();
        String user = sUserService.getSUser(userId);
        SUser sUser = CreateGson.createGson().fromJson(user, SUser.class);
        String role = sysRoleService.getRoleByUserId(userId);
        List<Map> maps = JSONObject.parseArray(role, Map.class);//一个人可能有多个角色
        //当前登录人所有的角色
        StringBuilder roles = new StringBuilder();
        for (int i = 0; i < maps.size(); i++) {
            Map map = maps.get(i);
            roles.append(map.get("roleCode") + ",");
        }
        String allRole = roles.toString();
        String provinceId = sUser.getProvinceId();//省id
        //获取所有任务编号和任务管理员
        List<TaskVo> taskManagers = fieldSurveyTaskService.getTaskManagers();
        //当前登录人(任务管理员)新建的所有任务
        List<String> taskCodeList = new ArrayList<>();
        //boolean flag = false;
        for (TaskVo taskVo : taskManagers) {
            String createUser = taskVo.getCreateUser();
            if (createUser.equals(userId)) {
                taskCodeList.add(taskVo.getTaskNum());
            }
        }
        List<BuildingEntity> buildingEntities = null;
        if (allRole.contains(FxfzConstants.YPG_COUN_GL_ROLE)) {
            buildingEntities = buildingReqository.queryBuilding(queryParams);
        }

        //国家业务员  查看 (如果是本人创建的或者组长需要加修改删除)
        else if (allRole.contains(FxfzConstants.YPG_COUN_YW_ROLE)) {
            buildingEntities = buildingReqository.queryBuilding(queryParams);

        }
        //省级管理员(各省查看各省的)  查看  修改  删除
        else if (allRole.contains(FxfzConstants.YPG_PRI_GL_ROLE)) {
            buildingEntities = buildingReqository.queryBuildingByProvince(queryParams, userId, provinceId, taskCodeList);

        }
        //省级业务员(各省查看各省的)查看   如果是本人创建的或者组长需要加修改删除)
        else if (allRole.contains(FxfzConstants.YPG_PRI_YW_ROLE)) {
            buildingEntities = buildingReqository.queryBuildingByProvince(queryParams, userId, provinceId, taskCodeList);

        } else {
            //无角色 本人
            buildingEntities = buildingReqository.queryBuildingDataByTeamMembers(queryParams, userId, taskCodeList);
        }
        return buildingEntities;
    }
    private List<String>  getTitle(BuildingEntity obj, Class<? extends Annotation> annotationClass) throws IllegalAccessException {
        List<String> result = new ArrayList<>();
        Field[] fields = obj.getClass().getDeclaredFields();
        for (Field field : fields) {
            field.setAccessible(true);
            Annotation annotation = field.getAnnotation(annotationClass);
            if (annotation != null) {
                if(annotation instanceof GcData){
                    GcData gcData = (GcData) annotation;
                    String fieldName = gcData.name();
                    result.add(fieldName);
                }else if(annotation instanceof GData){
                    GData gcData = (GData) annotation;
                    String fieldName = gcData.name();
                    result.add(fieldName);
                } else if(annotation instanceof DcData){
                    DcData gcData = (DcData) annotation;
                    String fieldName = gcData.name();
                    result.add(fieldName);
                }else if(annotation instanceof ZhData){
                    ZhData gcData = (ZhData) annotation;
                    String fieldName = gcData.name();
                    result.add(fieldName);
                }else if(annotation instanceof ZmData){
                    ZmData gcData = (ZmData) annotation;
                    String fieldName = gcData.name();
                    result.add(fieldName);
                }else if(annotation instanceof TData){
                    TData gcData = (TData) annotation;
                    String fieldName = gcData.name();
                    result.add(fieldName);
                }else if(annotation instanceof MData){
                    MData gcData = (MData) annotation;
                    String fieldName = gcData.name();
                    result.add(fieldName);
                }else if(annotation instanceof SData){
                    SData gcData = (SData) annotation;
                    String fieldName = gcData.name();
                    result.add(fieldName);
                }else if(annotation instanceof OData){
                    OData gcData = (OData) annotation;
                    String fieldName = gcData.name();
                    result.add(fieldName);
                }
            }
        }
        return result;
    }
    private List<String> getValue(BuildingEntity obj, Class<? extends Annotation> annotationClass) throws IllegalAccessException {
        List<String> result = new ArrayList<>();
        Field[] fields = obj.getClass().getDeclaredFields();
        for (Field field : fields) {
            field.setAccessible(true);
            Annotation annotation = field.getAnnotation(annotationClass);
            if (annotation != null) {
                if(annotation instanceof GcData){
                    Object val = field.get(obj);
                    result.add(PlatformObjectUtils.isEmpty(val)?"":val.toString());
                }else if(annotation instanceof GData){
                    Object val = field.get(obj);
                    result.add(PlatformObjectUtils.isEmpty(val)?"":val.toString());
                }else if(annotation instanceof DcData){
                    Object val = field.get(obj);
                    result.add(PlatformObjectUtils.isEmpty(val)?"":val.toString());
                }else if(annotation instanceof ZhData){
                    Object val = field.get(obj);
                    result.add(PlatformObjectUtils.isEmpty(val)?"":val.toString());
                }else if(annotation instanceof ZmData){
                    Object val = field.get(obj);
                    result.add(PlatformObjectUtils.isEmpty(val)?"":val.toString());
                }else if(annotation instanceof TData){
                    Object val = field.get(obj);
                    result.add(PlatformObjectUtils.isEmpty(val)?"":val.toString());
                }else if(annotation instanceof MData){
                    Object val = field.get(obj);
                    result.add(PlatformObjectUtils.isEmpty(val)?"":val.toString());
                }else if(annotation instanceof SData){
                    Object val = field.get(obj);
                    result.add(PlatformObjectUtils.isEmpty(val)?"":val.toString());
                }else if(annotation instanceof OData){
                    Object val = field.get(obj);
                    result.add(PlatformObjectUtils.isEmpty(val)?"":val.toString());
                }

            }
        }
        return result;
    }
    @Override
    public void exportBuilding(HttpServletResponse response, BuildingParams queryParams) throws IOException, IllegalAccessException {
        try{
            List<BuildingEntity> buildingEntities = getBuildingEntity(queryParams);
            //-------------------------------建筑物单体导出-----------------------------------
            List<BuildingEntity> gcList = new ArrayList<>();//高层建筑
            List<BuildingEntity> gList = new ArrayList<>();//钢结构
            List<BuildingEntity> dcgjhntList = new ArrayList<>();//多层钢筋混凝土结构
            List<BuildingEntity> zhList = new ArrayList<>();//砖混结构
            List<BuildingEntity> zmList = new ArrayList<>();//砖木结构
            List<BuildingEntity> tList = new ArrayList<>();//土结构
            List<BuildingEntity> mList = new ArrayList<>();//木结构
            List<BuildingEntity> sList = new ArrayList<>();//石结构
            List<BuildingEntity> qtList = new ArrayList<>();//其他结构
            if (!PlatformObjectUtils.isEmpty(buildingEntities)) {
                //去重
                //List<BuildingEntity> buildingEntityList = duplicateRemoval(buildingEntities);
                Set set = new HashSet();
                for (BuildingEntity buildingEntity : buildingEntities) {
                    if(set.add(buildingEntity)){
                        if (buildingEntity.getBuildingStructure().equals(BuildingStructureConstants.HIGH_STRUCTURE)) {
                            buildingEntity.setBuildingStructure("高层建筑");
                            gcList.add(buildingEntity);
                        } else if (buildingEntity.getBuildingStructure().equals(BuildingStructureConstants.STEEL_STRUCTURE)) {
                            buildingEntity.setBuildingStructure("钢结构");
                            gList.add(buildingEntity);
                        } else if (buildingEntity.getBuildingStructure().equals(BuildingStructureConstants.HNT_STRUCTURE)) {
                            buildingEntity.setBuildingStructure("多层钢筋混凝土结构");
                            dcgjhntList.add(buildingEntity);
                        } else if (buildingEntity.getBuildingStructure().equals(BuildingStructureConstants.ZH_STRUCTURE)) {
                            buildingEntity.setBuildingStructure("砖混结构");
                            zhList.add(buildingEntity);
                        } else if (buildingEntity.getBuildingStructure().equals(BuildingStructureConstants.ZM_STRUCTURE)) {
                            buildingEntity.setBuildingStructure("砖木结构");
                            zmList.add(buildingEntity);
                        } else if (buildingEntity.getBuildingStructure().equals(BuildingStructureConstants.SOIL_STRUCTURE)) {
                            buildingEntity.setBuildingStructure("土结构");
                            tList.add(buildingEntity);
                        } else if (buildingEntity.getBuildingStructure().equals(BuildingStructureConstants.WOOD_STRUCTURE)) {
                            buildingEntity.setBuildingStructure("木结构");
                            mList.add(buildingEntity);
                        } else if (buildingEntity.getBuildingStructure().equals(BuildingStructureConstants.STONE_STRUCTURE)) {
                            buildingEntity.setBuildingStructure("石结构");
                            sList.add(buildingEntity);
                        } else if (buildingEntity.getBuildingStructure().equals(BuildingStructureConstants.OTHER_STRUCTURE)) {
                            buildingEntity.setBuildingStructure("其他结构");
                            qtList.add(buildingEntity);
                        }
                    }
                }

                String name = "建筑物单体数据.xls";
                response.setContentType("application/octet-stream ");
                response.setHeader("Connection", "close"); // 表示不能用浏览器直接打开
                response.setHeader("Accept-Ranges", "bytes");// 告诉客户端允许断点续传多线程连接下载
                response.setHeader("Content-Disposition",
                        "attachment;filename=" + new String(name.getBytes("GB2312"), "ISO8859-1"));
                response.setCharacterEncoding("UTF-8");
                OutputStream out = response.getOutputStream();
                HSSFWorkbook workbook = new HSSFWorkbook();

                // 样式设置
                HSSFCellStyle columnHeadStyle = workbook.createCellStyle();
                columnHeadStyle.setFillPattern(FillPatternType.NO_FILL); // 背景
                columnHeadStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex()); // 背景色AQUA.getIndex()
                columnHeadStyle.setBorderBottom(BorderStyle.THIN); // 下边框
                columnHeadStyle.setBorderLeft(BorderStyle.THIN);// 左边框
                columnHeadStyle.setBorderTop(BorderStyle.THIN);// 上边框
                columnHeadStyle.setBorderRight(BorderStyle.THIN);// 右边框
                columnHeadStyle.setAlignment(HorizontalAlignment.CENTER);//水平居中
                columnHeadStyle.setVerticalAlignment(VerticalAlignment.CENTER);// 上下居中
                columnHeadStyle.setWrapText(true);//自动换行
                HSSFFont headFont = workbook.createFont();
                headFont.setFontName("黑体");
                headFont.setFontHeightInPoints((short) 12);// 字体大小
                columnHeadStyle.setFont(headFont);
                // 全局样式设置
                HSSFCellStyle allStyle = workbook.createCellStyle();
                allStyle.setFillPattern(FillPatternType.NO_FILL); // 背景
                allStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex());// 填充白色
                allStyle.setBorderBottom(BorderStyle.THIN); // 下边框
                allStyle.setBorderLeft(BorderStyle.THIN);// 左边框
                allStyle.setBorderTop(BorderStyle.THIN);// 上边框
                allStyle.setBorderRight(BorderStyle.THIN);// 右边框
                allStyle.setAlignment(HorizontalAlignment.CENTER);//水平居中
                allStyle.setVerticalAlignment(VerticalAlignment.CENTER);// 上下居中
                allStyle.setWrapText(true);//自动换行

                HSSFSheet sheet0 = workbook.createSheet("高层建筑");
                if(gcList.size()>0){
                    List<String> title = new ArrayList<>();
                    int startIndex = 0;
                    for (int k = 0; k < gcList.size(); k++) {
                        //rowk.setHeight((short) 600);
                        BuildingEntity buildingEntity = gcList.get(k);
                        if (k == 0) {
                            HSSFRow rowk = sheet0.createRow(startIndex++);
                            rowk.setHeightInPoints((short) 30);
                            title = getTitle(buildingEntity,GcData.class);
                            //设置标题
                            for (int i = 0; i < title.size(); i++) {
                                HSSFCell cel1_i = rowk.createCell(i);
                                cel1_i.setCellValue(title.get(i));
                                cel1_i.setCellStyle(columnHeadStyle);
                            }
                        }
                        List<String> value = getValue(buildingEntity,GcData.class);
                        HSSFRow rowk = sheet0.createRow(startIndex++);
                        rowk.setHeightInPoints((short) 30);
                        for (int i = 0; i < title.size(); i++) {
                            HSSFCell celk_i = rowk.createCell(i);
                            celk_i.setCellValue(value.get(i));
                            celk_i.setCellStyle(allStyle);
                            //sheet0.autoSizeColumn((short) i);
                        }
                    }
                }else{
                    String[] sheet0HeadTitle = {"任务编号", "建筑编号", "建筑地点-省", "建筑地点-市", "建筑地点-县", "建筑地点-乡", "经度", "纬度", "设防烈度", "建造年代", "用途", "层数", "高度（m）", "地形条件（有无山体滑坡、山崩危险）", "地基情况（有无下部软弱土层）", "平面型规则", "竖向规则性", "出屋面构件", "房屋状况", "程度描述", "抗震能力", "备注", "建筑结构", "高层建筑-结构类型"};
                    HSSFRow rowk = sheet0.createRow(0);
                    rowk.setHeightInPoints(30);
                    for (int i = 0; i < sheet0HeadTitle.length; i++) {
                        HSSFCell cel1_i = rowk.createCell(i);
                        cel1_i.setCellValue(new HSSFRichTextString(sheet0HeadTitle[i]));
                        cel1_i.setCellStyle(columnHeadStyle);
                    }
                }


            HSSFSheet sheet1 = workbook.createSheet("钢结构");
            String[] sheet1HeadTitle = {"任务编号", "建筑编号", "建筑地点-省", "建筑地点-市", "建筑地点-县", "建筑地点-乡", "经度", "纬度", "设防烈度", "建造年代", "用途", "层数", "高度（m）", "地形条件（有无山体滑坡、山崩危险）", "地基情况（有无下部软弱土层）", "平面型规则", "竖向规则性", "出屋面构件", "房屋状况", "程度描述", "抗震能力", "备注", "建筑结构", "钢结构-结构类型"};
            if(gList.size()>0){
                List<String> title = new ArrayList<>();
                int startIndex = 0;
                for (int k = 0; k < gList.size(); k++) {
                    //rowk.setHeight((short) 600);
                    BuildingEntity buildingEntity = gList.get(k);
                    if (k == 0) {
                        HSSFRow rowk = sheet1.createRow(startIndex++);
                        rowk.setHeightInPoints((short) 30);
                        title = getTitle(buildingEntity, GData.class);
                        //设置标题
                        for (int i = 0; i < title.size(); i++) {
                            HSSFCell cel1_i = rowk.createCell(i);
                            cel1_i.setCellValue(title.get(i));
                            cel1_i.setCellStyle(columnHeadStyle);
                        }
                    }
                    List<String> value = getValue(buildingEntity,GData.class);
                    HSSFRow rowk = sheet1.createRow(startIndex++);
                    rowk.setHeightInPoints((short) 30);
                    for (int i = 0; i < title.size(); i++) {
                        HSSFCell celk_i = rowk.createCell(i);
                        celk_i.setCellValue(value.get(i));
                        celk_i.setCellStyle(allStyle);
                        //sheet1.autoSizeColumn((short) i);
                    }
                }
            }else{
                HSSFRow rowk = sheet1.createRow(0);
                rowk.setHeightInPoints(30);
                for (int i = 0; i < sheet1HeadTitle.length; i++) {
                    HSSFCell cel1_i = rowk.createCell(i);
                    cel1_i.setCellValue(new HSSFRichTextString(sheet1HeadTitle[i]));
                    cel1_i.setCellStyle(columnHeadStyle);
                }
            }

            HSSFSheet sheet2 = workbook.createSheet("多层钢筋混凝土结构");
            String[] sheet2HeadTitle = {"任务编号", "建筑编号", "建筑地点-省", "建筑地点-市", "建筑地点-县", "建筑地点-乡", "经度", "纬度", "设防烈度", "建造年代", "用途", "层数", "高度（m）", "地形条件（有无山体滑坡、山崩危险）", "地基情况（有无下部软弱土层）", "平面型规则", "竖向规则性", "出屋面构件", "房屋状况", "程度描述", "抗震能力", "备注", "建筑结构", "填充墙与柱连接方式", "楼梯间位置（是否在近端或转角）", "主要柱截面尺寸（mm*mm）", "主要梁截面尺寸（mm*mm）", "薄弱环节", "最大柱间距(m)", "最大层高(m)", "梁最大跨度(m)"};
            if(dcgjhntList.size()>0){
                List<String> title = new ArrayList<>();
                int startIndex = 0;
                for (int k = 0; k < dcgjhntList.size(); k++) {
                    //rowk.setHeight((short) 600);
                    BuildingEntity buildingEntity = dcgjhntList.get(k);
                    if (k == 0) {
                        HSSFRow rowk = sheet2.createRow(startIndex++);
                        rowk.setHeightInPoints((short) 30);
                        title = getTitle(buildingEntity, DcData.class);
                        //设置标题
                        for (int i = 0; i < title.size(); i++) {
                            HSSFCell cel1_i = rowk.createCell(i);
                            cel1_i.setCellValue(title.get(i));
                            cel1_i.setCellStyle(columnHeadStyle);
                        }
                    }
                    List<String> value = getValue(buildingEntity,DcData.class);
                    HSSFRow rowk = sheet2.createRow(startIndex++);
                    rowk.setHeightInPoints((short) 30);
                    for (int i = 0; i < title.size(); i++) {
                        HSSFCell celk_i = rowk.createCell(i);
                        celk_i.setCellValue(value.get(i));
                        celk_i.setCellStyle(allStyle);
                        //sheet1.autoSizeColumn((short) i);
                    }
                }
            }else{
                HSSFRow rowk = sheet2.createRow(0);
                rowk.setHeightInPoints(30);
                for (int i = 0; i < sheet2HeadTitle.length; i++) {
                    HSSFCell cel1_i = rowk.createCell(i);
                    cel1_i.setCellValue(new HSSFRichTextString(sheet2HeadTitle[i]));
                    cel1_i.setCellStyle(columnHeadStyle);
                }
            }

            HSSFSheet sheet3 = workbook.createSheet("砖混结构");
            if(zhList.size()>0){
                List<String> title = new ArrayList<>();
                int startIndex = 0;
                for (int k = 0; k < zhList.size(); k++) {
                    //rowk.setHeight((short) 600);
                    BuildingEntity buildingEntity = zhList.get(k);
                    if (k == 0) {
                        HSSFRow rowk = sheet3.createRow(startIndex++);
                        rowk.setHeightInPoints((short) 30);
                        title = getTitle(buildingEntity, ZhData.class);
                        //设置标题
                        for (int i = 0; i < title.size(); i++) {
                            HSSFCell cel1_i = rowk.createCell(i);
                            cel1_i.setCellValue(title.get(i));
                            cel1_i.setCellStyle(columnHeadStyle);
                        }
                    }
                    List<String> value = getValue(buildingEntity,ZhData.class);
                    HSSFRow rowk = sheet3.createRow(startIndex++);
                    rowk.setHeightInPoints((short) 30);
                    for (int i = 0; i < title.size(); i++) {
                        HSSFCell celk_i = rowk.createCell(i);
                        celk_i.setCellValue(value.get(i));
                        celk_i.setCellStyle(allStyle);
                        //sheet1.autoSizeColumn((short) i);
                    }
                }
            }else{
                String[] sheet3HeadTitle = {"任务编号", "建筑编号", "建筑地点-省", "建筑地点-市", "建筑地点-县", "建筑地点-乡", "经度", "纬度", "设防烈度", "建造年代", "用途", "层数", "高度（m）", "地形条件（有无山体滑坡、山崩危险）", "地基情况（有无下部软弱土层）", "平面型规则", "竖向规则性", "出屋面构件", "房屋状况", "程度描述", "抗震能力", "备注", "建筑结构", "楼盖类型", "屋盖类型", "墙体材料", "墙体厚度-内墙（mm）", "墙体厚度-外墙（mm）", "砂浆类别", "砂浆强度", "承重体系", "承重墙砌筑方式", "楼梯间位置（是否在近端或转角）", "大洞窗,转角窗", "构造柱", "圈梁"};
                HSSFRow rowk = sheet3.createRow(0);
                rowk.setHeightInPoints(30);
                for (int i = 0; i < sheet3HeadTitle.length; i++) {
                    HSSFCell cel1_i = rowk.createCell(i);
                    cel1_i.setCellValue(new HSSFRichTextString(sheet3HeadTitle[i]));
                    cel1_i.setCellStyle(columnHeadStyle);
                }
            }


            HSSFSheet sheet4 = workbook.createSheet("砖木结构");
            if(zmList.size()>0){
                List<String> title = new ArrayList<>();
                int startIndex = 0;
                for (int k = 0; k < zmList.size(); k++) {
                    //rowk.setHeight((short) 600);
                    BuildingEntity buildingEntity = zmList.get(k);
                    if (k == 0) {
                        HSSFRow rowk = sheet4.createRow(startIndex++);
                        rowk.setHeightInPoints((short) 30);
                        title = getTitle(buildingEntity, ZmData.class);
                        //设置标题
                        for (int i = 0; i < title.size(); i++) {
                            HSSFCell cel1_i = rowk.createCell(i);
                            cel1_i.setCellValue(title.get(i));
                            cel1_i.setCellStyle(columnHeadStyle);
                        }
                    }
                    List<String> value = getValue(buildingEntity,ZmData.class);
                    HSSFRow rowk = sheet4.createRow(startIndex++);
                    rowk.setHeightInPoints((short) 30);
                    for (int i = 0; i < title.size(); i++) {
                        HSSFCell celk_i = rowk.createCell(i);
                        celk_i.setCellValue(value.get(i));
                        celk_i.setCellStyle(allStyle);
                        //sheet1.autoSizeColumn((short) i);
                    }
                }
            }else{
                String[] sheet4HeadTitle = {"任务编号", "建筑编号", "建筑地点-省", "建筑地点-市", "建筑地点-县", "建筑地点-乡", "经度", "纬度", "设防烈度", "建造年代", "用途", "层数", "高度（m）", "地形条件（有无山体滑坡、山崩危险）", "地基情况（有无下部软弱土层）", "平面型规则", "竖向规则性", "出屋面构件", "房屋状况", "程度描述", "抗震能力", "备注", "建筑结构", "屋盖类型", "墙体材料", "砂浆", "承重体系", "横墙开洞面积（水平全截面面积1/3）", "构造柱", "圈梁"};
                HSSFRow rowk = sheet4.createRow(0);
                rowk.setHeightInPoints(30);
                for (int i = 0; i < sheet4HeadTitle.length; i++) {
                    HSSFCell cel1_i = rowk.createCell(i);
                    cel1_i.setCellValue(new HSSFRichTextString(sheet4HeadTitle[i]));
                    cel1_i.setCellStyle(columnHeadStyle);
                }
            }

            HSSFSheet sheet5 = workbook.createSheet("土结构");
            String[] sheet5HeadTitle = {"任务编号", "建筑编号", "建筑地点-省", "建筑地点-市", "建筑地点-县", "建筑地点-乡", "经度", "纬度", "设防烈度", "建造年代", "用途", "层数", "高度（m）", "地形条件（有无山体滑坡、山崩危险）", "地基情况（有无下部软弱土层）", "平面型规则", "竖向规则性", "出屋面构件", "房屋状况", "程度描述", "抗震能力", "备注", "建筑结构", "硬山搁檀", "墙体", "墙体建筑方式", "有无墙体圈梁", "墙体延性材料", "门窗洞口宽度", "承重墙最大间距", "屋面形式", "屋面材料", "屋楼盖拉结措施"};
            if(tList.size()>0){
                List<String> title = new ArrayList<>();
                int startIndex = 0;
                for (int k = 0; k < tList.size(); k++) {
                    //rowk.setHeight((short) 600);
                    BuildingEntity buildingEntity = tList.get(k);
                    if (k == 0) {
                        HSSFRow rowk = sheet5.createRow(startIndex++);
                        rowk.setHeightInPoints((short) 30);
                        title = getTitle(buildingEntity, TData.class);
                        //设置标题
                        for (int i = 0; i < title.size(); i++) {
                            HSSFCell cel1_i = rowk.createCell(i);
                            cel1_i.setCellValue(title.get(i));
                            cel1_i.setCellStyle(columnHeadStyle);
                        }
                    }
                    List<String> value = getValue(buildingEntity,TData.class);
                    HSSFRow rowk = sheet5.createRow(startIndex++);
                    rowk.setHeightInPoints((short) 30);
                    for (int i = 0; i < title.size(); i++) {
                        HSSFCell celk_i = rowk.createCell(i);
                        celk_i.setCellValue(value.get(i));
                        celk_i.setCellStyle(allStyle);
                        //sheet1.autoSizeColumn((short) i);
                    }
                }
            }else{
                HSSFRow rowk = sheet5.createRow(0);
                rowk.setHeightInPoints(30);
                for (int i = 0; i < sheet5HeadTitle.length; i++) {
                    HSSFCell cel1_i = rowk.createCell(i);
                    cel1_i.setCellValue(new HSSFRichTextString(sheet5HeadTitle[i]));
                    cel1_i.setCellStyle(columnHeadStyle);
                }
            }

            HSSFSheet sheet6 = workbook.createSheet("木结构");
            String[] sheet6HeadTitle = {"任务编号", "建筑编号", "建筑地点-省", "建筑地点-市", "建筑地点-县", "建筑地点-乡", "经度", "纬度", "设防烈度", "建造年代", "用途", "层数", "高度（m）", "地形条件（有无山体滑坡、山崩危险）", "地基情况（有无下部软弱土层）", "平面型规则", "竖向规则性", "出屋面构件", "房屋状况", "程度描述", "抗震能力", "备注", "建筑结构", "结构类型", "柱间支撑", "木柱接长处接榫是否牢固", "节点", "木径梢径", "柱脚与基础锚固", "山尖墙", "围护墙", "墙体连接"};
            if(mList.size()>0){
                List<String> title = new ArrayList<>();
                int startIndex = 0;
                for (int k = 0; k < mList.size(); k++) {
                    //rowk.setHeight((short) 600);
                    BuildingEntity buildingEntity = mList.get(k);
                    if (k == 0) {
                        HSSFRow rowk = sheet6.createRow(startIndex++);
                        rowk.setHeightInPoints((short) 30);
                        title = getTitle(buildingEntity, MData.class);
                        //设置标题
                        for (int i = 0; i < title.size(); i++) {
                            HSSFCell cel1_i = rowk.createCell(i);
                            cel1_i.setCellValue(title.get(i));
                            cel1_i.setCellStyle(columnHeadStyle);
                        }
                    }
                    List<String> value = getValue(buildingEntity,MData.class);
                    HSSFRow rowk = sheet6.createRow(startIndex++);
                    rowk.setHeightInPoints((short) 30);
                    for (int i = 0; i < title.size(); i++) {
                        HSSFCell celk_i = rowk.createCell(i);
                        celk_i.setCellValue(value.get(i));
                        celk_i.setCellStyle(allStyle);
                        //sheet1.autoSizeColumn((short) i);
                    }
                }
            }else{
                HSSFRow rowk = sheet6.createRow(0);
                rowk.setHeightInPoints(30);
                for (int i = 0; i < sheet6HeadTitle.length; i++) {
                    HSSFCell cel1_i = rowk.createCell(i);
                    cel1_i.setCellValue(new HSSFRichTextString(sheet6HeadTitle[i]));
                    cel1_i.setCellStyle(columnHeadStyle);
                }
            }

            HSSFSheet sheet7 = workbook.createSheet("石结构");
            String[] sheet7HeadTitle = {"任务编号", "建筑编号", "建筑地点-省", "建筑地点-市", "建筑地点-县", "建筑地点-乡", "经度", "纬度", "设防烈度", "建造年代", "用途", "层数", "高度（m）", "地形条件（有无山体滑坡、山崩危险）", "地基情况（有无下部软弱土层）", "平面型规则", "竖向规则性", "出屋面构件", "房屋状况", "程度描述", "抗震能力", "备注", "建筑结构", "墙体材料", "承重方式", "上下楼层结构类型", "楼屋盖类型", "横墙最大间距（m）", "横墙开洞面积大于或小于水平全截面面积1/3", "纵横墙连接", "圈梁", "四角构造柱"};
            if(sList.size()>0){
                List<String> title = new ArrayList<>();
                int startIndex = 0;
                for (int k = 0; k < sList.size(); k++) {
                    //rowk.setHeight((short) 600);
                    BuildingEntity buildingEntity = sList.get(k);
                    if (k == 0) {
                        HSSFRow rowk = sheet7.createRow(startIndex++);
                        rowk.setHeightInPoints((short) 30);
                        title = getTitle(buildingEntity, SData.class);
                        //设置标题
                        for (int i = 0; i < title.size(); i++) {
                            HSSFCell cel1_i = rowk.createCell(i);
                            cel1_i.setCellValue(title.get(i));
                            cel1_i.setCellStyle(columnHeadStyle);
                        }
                    }
                    List<String> value = getValue(buildingEntity,SData.class);
                    HSSFRow rowk = sheet7.createRow(startIndex++);
                    rowk.setHeightInPoints((short) 30);
                    for (int i = 0; i < title.size(); i++) {
                        HSSFCell celk_i = rowk.createCell(i);
                        celk_i.setCellValue(value.get(i));
                        celk_i.setCellStyle(allStyle);
                        //sheet1.autoSizeColumn((short) i);
                    }
                }
            }else{
                HSSFRow rowk = sheet7.createRow(0);
                rowk.setHeightInPoints(30);
                for (int i = 0; i < sheet7HeadTitle.length; i++) {
                    HSSFCell cel1_i = rowk.createCell(i);
                    cel1_i.setCellValue(new HSSFRichTextString(sheet7HeadTitle[i]));
                    cel1_i.setCellStyle(columnHeadStyle);
                }
            }

            HSSFSheet sheet8 = workbook.createSheet("其他结构");
            String[] sheet8HeadTitle = {"任务编号", "建筑编号", "建筑地点-省", "建筑地点-市", "建筑地点-县", "建筑地点-乡", "经度", "纬度", "设防烈度", "建造年代", "用途", "层数", "高度（m）", "地形条件（有无山体滑坡、山崩危险）", "地基情况（有无下部软弱土层）", "平面型规则", "竖向规则性", "出屋面构件", "房屋状况", "程度描述", "抗震能力", "备注", "建筑结构"};
            if(qtList.size()>0){
                List<String> title = new ArrayList<>();
                int startIndex = 0;
                for (int k = 0; k < qtList.size(); k++) {
                    //rowk.setHeight((short) 600);
                    BuildingEntity buildingEntity = qtList.get(k);
                    if (k == 0) {
                        HSSFRow rowk = sheet8.createRow(startIndex++);
                        rowk.setHeightInPoints((short) 30);
                        title = getTitle(buildingEntity, OData.class);
                        //设置标题
                        for (int i = 0; i < title.size(); i++) {
                            HSSFCell cel1_i = rowk.createCell(i);
                            cel1_i.setCellValue(title.get(i));
                            cel1_i.setCellStyle(columnHeadStyle);
                        }
                    }
                    List<String> value = getValue(buildingEntity,OData.class);
                    HSSFRow rowk = sheet8.createRow(startIndex++);
                    rowk.setHeightInPoints((short) 30);
                    for (int i = 0; i < title.size(); i++) {
                        HSSFCell celk_i = rowk.createCell(i);
                        celk_i.setCellValue(value.get(i));
                        celk_i.setCellStyle(allStyle);
                        //sheet1.autoSizeColumn((short) i);
                    }
                }
            }else{
                HSSFRow rowk = sheet8.createRow(0);
                rowk.setHeightInPoints(30);
                for (int i = 0; i < sheet8HeadTitle.length; i++) {
                    HSSFCell cel1_i = rowk.createCell(i);
                    cel1_i.setCellValue(new HSSFRichTextString(sheet8HeadTitle[i]));
                    cel1_i.setCellStyle(columnHeadStyle);
                }
            }
            //            for (int k = 0; k <= qtList.size(); k++) {
//                HSSFRow rowk = sheet8.createRow(k);
//                rowk.setHeightInPoints(30);
//                for (int i = 0; i < sheet8HeadTitle.length; i++) {
//                    if (k == 0) {
//                        HSSFCell cel1_i = rowk.createCell(i);
//                        cel1_i.setCellValue(new HSSFRichTextString(sheet8HeadTitle[i]));
//                        cel1_i.setCellStyle(columnHeadStyle);
//                    } else {
//                        QtExcelVo qtExcelVo = new QtExcelVo();
//                        SpringUtil.copyPropertiesIgnoreNull(qtList.get(k - 1), qtExcelVo);
//                        String[] gValues = PoiExcelUtil.objectChangeArray(qtExcelVo);
//                        HSSFCell celk_i = rowk.createCell(i);
//                        if (!PlatformObjectUtils.isEmpty(gValues[i])) {
//                            celk_i.setCellValue(new HSSFRichTextString(gValues[i]));
//                            celk_i.setCellStyle(allStyle);
//                        } else {
//                            celk_i.setCellStyle(allStyle);
//                        }
//                    }
//                    sheet8.autoSizeColumn((short) i);
//                }
//            }
                workbook.write(out);
                if (out != null) {
                    out.flush();
                    out.close();
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }

    }

    private List<BuildingEntity> duplicateRemoval(List<BuildingEntity> list) {
        Set set = new HashSet();
        List<BuildingEntity> newList = new ArrayList<>();
        for (Iterator iter = list.iterator(); iter.hasNext(); ) {
            Object next = iter.next();
            if (set.add(next)) {
                newList.add((BuildingEntity) next);
            }
        }
        list.clear();
        list.addAll(newList);
        return list;
    }


    // public boolean export(HttpServletResponse response,List<BuildingEntity> buildingEntities) throws IOException {


    public static void main(String[] args) {
        String[] gValues = {"1"};
        if (!PlatformObjectUtils.isEmpty(gValues[1])) {
            System.err.println("1111");
        }
    }


}
